Ubuntu starts SSH service

Time:2022-7-10

Install SSH

ubuntu

sudo apt-get install openssh-server

start-up

service sshd start

View SSH running status

service ssh status

Turn off firewall

sudo ufw disable

Start SSH command automatically after startup

sudo systemctl enable ssh

Turn off SSH boot auto start command

sudo systemctl disable ssh

Single start SSH

sudo systemctl start ssh

Single SSH shutdown

sudo systemctl stop ssh

Restart the system after setting

reboot
  • Check whether SSH is started. Seeing active: active (running) indicates success
sudo systemctl status ssh

Set allow login with root user

1. Switch to root

After the default installation is completed, you do not know the password of root user, so how to apply root permission?

  • Sudo command
sudo

In this way, you can get the authority of super user by entering the current administrator user password. But by default, the root permission is invalid after 5 minutes.

  • sudo -i
sudo -i

By entering the password of the current administrator user in this way, you can enter the root user.

  • If you want to use root permission all the time, to switch to root user through Su, we must first reset the password of root user:
sudo passwd root

In this way, you can set the password of root user, and then you cansuFreely switch to the root user. Su “King” or exit to return to user permission

su

2. Change the root password

Log in as root and execute:

Passwd user name

Then, according to the prompt, enter the new password, and enter the new password again, and the system will prompt that the password has been successfully modified.
Modify configuration file

3. Allow root user terminal login

sudo vim /etc/ssh/sshd_config

Find and comment out this line with “#”PermitRootLogin prohibit-password, the results are as follows

# PermitRootLogin prohibit-password

Create a new row to add:

PermitRootLogin yes

Restart service

sudo service ssh restart

Set password

sudo passwd root

Public key login

Enter command

ssh-keygen -t rsa -C "[email protected]"

Not in the Linux root directory SSH directory

ssh localhost

.sshIt is a folder for recording password information. If you have not logged inrootIf so, No.sshFolder, so loginlocalhost, and enter the password.

Add certificate

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCVAmnEqMs1gC6Rtt5a/KicNmBkdecHzpNLBInhNMYBreZWeL0KmGPNPGXclvTfDl6i2IDkcGFcmNQ7utBQGoLVvnSeZd4GndBPDdn/0OuOhFetzAzFuAPXBdbcoVs7LPP6LaF+ba1qsABY76KU90IEP7QqpSpOaw9YXeTADj3kO4eefi/9el5ND8EuoW6N+Xza01x1XBI0bw8ivD6+VJ9RM38C4Ggd/Rp9KlA5eN9TKq7AYk3TnN5Wbhx+dUaYOSaqrDgzMh26zi/TPsF0lW420VgSl5RR+9QjfFC+ipMFnGjOIFFEKR5OD5BD2QYIVGbm/RG7I/tU1EJNbWdXZ+fr [email protected]

Add public key toauthorized_keysFolder

SSH config syntax keyword

  • Host: alias
  • Hostname: host (server) IP
  • Port: Port
  • User: user name
  • Identityfile: secret key file path

usage

.ssh/config。 If not, create a new one

host 'biter'
    HostName 192.168.31.68
    Port 22
    User root

You can use the abovealiasLog in to the Linux service

ssh biter

If there are multiple hosts, multiple hosts can be configured

host 'biter'
    HostName 192.168.31.68
    Port 22
    User root
    
host 'biter1'
    HostName 192.168.31.68
    Port 22
    User root
    
host 'biter2'
    HostName 192.168.31.68
    Port 22
    User root

Recommended Today

Use of String

1. Use of String String s1 = “abc”;//How literals are defined String s2 = “abc”; System.out.println(s1==s2)//true, s1, s2 point to the same address   1. String is declared final and cannot be inherited2. The String class implements the Serializable interface: indicating that strings support serialization,Implements the Comparable interface: indicates that String can be compared in […]