We all use ssh logins for server. May be production servers and may be deployment servers. We are all used to login using passwords but if we have many servers , remembering all passwords might be an issue. Hence, for ease of use, a small thing we can do is login to our servers without passwords. The logic behind this is putting in public keys for authorized users in .ssh/authorized_keys file.
This might help in security as well because the admin can do this procedure and authorize/ de-authorize a system from accessing the server. The passwords will remain only with admin and his/her team and hence risk of password leaking is less!
Step 1: Generate a public key:
ssh-keygen -t rsa
Step 2: Copy the public key
The public key is by default stored in ~/.ssh/id_rsa.pub file Open this file in your favourite editor and copy the key.
You can also use xclip for this.
Step 3: Login to your server
ssh username@servername
Step 4: Paste the key in ~/.ssh/authorized_keys file.
A single line command to do this:
cat .ssh/id_rsa.pub | ssh username@server 'cat >> .ssh/authorized_keys'
This should do the trick!
Hope it helps!