Skip to main content

SSH - replace password with your RSA key

Typing passwords for every ssh server can be annoying. But we can use our RSA key to login without it.
I assume that you have already RSA key generated, and it's saved in default .ssh/ path.

On your local machine type:

ssh-copy-id -i .ssh/id_rsa.pub yourlogin@ssh-domain.com

You can add any port like in normal ssh connection if you needed:

ssh-copy-id -i .ssh/id_rsa.pub yourlogin@ssh-domain.com -p 222

 After that, you will be prompted to enter ssh password, and it will be last time. Try to connect, should works.

How ssh-copy-id works

From documentation on:

https://www.ssh.com/ssh/copy-id

ssh-copy-id uses the SSH protocol to connect to the target host and upload the SSH user key. The command edits the authorized_keys file on the server. It creates the .ssh directory if it doesn't exist. It creates the authorized keys file if it doesn't exist. Effectively, ssh key copied to server.

It also checks if the key already exists on the server. Unless the -f option is given, each key is only added to the authorized keys file once.

It further ensures that the key files have appropriate permissions. Generally, the user's home directory or any file or directory containing keys files should not be writable by anyone else. Otherwise someone else could add new authorized keys for the user and gain access. Private key files should not be readable by anyone else.

In short, all data is saved inside .ssh/authorized_keys file, so you can connect to your remote server, and check it:

cat .ssh/authorized_keys

 

Add new comment

CAPTCHA

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

We use cookies on our website to enhance your user experience. We also use Google analytics and ads.

Click here to read more I've read it