Ubuntu Remote login server ssh installation and configuration details

  • 2020-06-03 09:09:36
  • OfStack

The following commands operate on the server side if they do not have bold notes indicating that they operate on the local computer

1 Install and log in remotely using ssh

Update software list


sudo apt-get update

Update local software


sudo apt-get upgrade

Install ssh services


sudo apt-get install openssh-server

Start the ssh service


sudo /etc/init.d/ssh start

View the local IP address

The inet field is followed by your IP address


sudo ifconfig

Remote login

Type ssh in the local computer terminal < username > @ < server IP >

Here we assume that the user name and IP address on the server are xiaoming and 192.168.1.1. Please automatically replace them with your own, which will not be described later


ssh xiaoming@192.168.1.1

2. Set remote login shortcut key

It is cumbersome to enter a username and password every time you log in to the server, and the IP address is hard to remember, so you can change the.bashrc file to set the fast key for remote login

Open the.bashrc configuration file using the editor on your local computer


sudo vi ~/.bashrc

Add the following at the end


alias server='ssh xiaoming@192.168.1.1'

Close the file and reload the configuration file by entering the following command line


source ~/.bashrc

Later, you can log in the server remotely by typing server into the terminal

Add public key authentication

Having to enter the server's password every time you log in is cumbersome and not very secure, so you can add public key authentication to avoid the hassle and security of entering the password

3.1 Generate key pairs

Enter the following command on your local computer


ssh-keygen

The following will be prompted


sudo apt-get upgrade
0

Direct enter to determine on the line

Next, the system will prompt you to set the password to ensure the security of the key, 1 direct enter confirm the password is left blank, so that you can use the private key authentication time to avoid the trouble of entering the password

Switch to the key pair directory


sudo apt-get upgrade
1

At this point, you can see the generated private keys id_rsa and the public key ES93en_rsa.pub, in the ~/.ssh directory, remember not to expose your private key id_rsa

3.2 Copy public key to remote server

Enter the following command on your local computer


sudo apt-get upgrade
2

3.3 Done!

To complete this configuration, you can enter the following command from your local computer to remotely log on to ssh


server

Related articles: