Set up passwordless ssh login to remote server
Tips
It is annoying to enter password every time when connecting to server using ssh. How can we avoid that?
Question
ssh remote_username@server_ip_address
For the first time connecting to a server, you may see:
The authenticity of host 'server_ip_address' can't be established. key fingerprint is SOME_CONTENTS This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])?
Then enter password to connect.
That step will create some files in the path ~/.ssh/
Later on, to avoid entering password at each time logging in to the server, do the following:
Solution
- Generate SSH Public Key
Ref: https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key
ssh-keygen
- Add device ssh key to remote server
Ref1: https://linuxize.com/post/how-to-setup-passwordless-ssh-login/
ssh-copy-id remote_username@server_ip_address
With entering password, there should be a notice
Number of key(s) added: 1
Then you can connect to server without password by doing ssh remote_username@server_ip_address
3. Make it even esier
nano ~/.ssh/config
In the file ~/.ssh/config
, write down
Host THE_SERVER_NICKNAME
HostName server_ip_address
User remote_username
Then you can connect to server without password with the nickname ssh THE_SERVER_NICKNAME