Skip to content

[Linux] Configure SSH Config for Remote Server Login

SSH is the abbreviation of Secure Shell, which is an encrypted network transmission protocol. Its main function is to allow user to connect to the server.

The method of use is easy:

ssh username@server_ip

And key in the user’s password and remote login.

But if you need to key in the password every times, it is trouble. So we can configure the ssh config to login remote server without password, and reduce the chance of password leakage.


How to do it

Use the following command to generate RSA key:

ssh-keygen -t rsa

If no additional configuration is required, we only need to press Enter. And then our key will store in ~/.ssh (default).

The generated files are id_rsa and id_rsa.pub.

  • id_rsa.pub: This is the public key, which need to be placed on the remote server for authentication
  • id_rsa: This is the private key, it must be stored on you local computer.

Configure private key

If there is no hidden folder ~/.ssh in the user directory, you can create it by yourself:

mkdir .ssh


And then edit the config file.

vim ~/.ssh/config


Add the following content:

Host HOST_NAME
    HostName REMOTE_HOST_IP
    Port SSH_PORT (Default is 22)
    User USER_NAME
    IdentityFile ~/.ssh/id_rsa

Configure public key

Copy the public key in ~/.ssh/id_rsa.pub just now, connect to the server remotely, and use

vim ~/.ssh/authorized_keys

To copy the key directly into it.


TEST

Now that both sides are configured, do you remember the alias HOST_NAME that you just preset?

Use the following command, you should be able to log in without a password:

ssh HOST_NAME

References

Tags:

1 thought on “[Linux] Configure SSH Config for Remote Server Login”

  1. Pingback: remote server login linux - logindataworld

Leave a Reply