SSH without password2023-09-05

tldr; using ssh-copy-id

If you're tired of typing your password every time you want to SSH into a remote server, ssh-copy-id is the tool for you. It allows you to copy your public key to a remote server's authorized_keys file, effectively giving you passwordless access to that server.

Step 1: Generate a Key Pair (Skip if you already have one)

If you haven't already, you'll need to generate a key pair on your local machine. This can be done with the following command:

ssh-keygen

You will be prompted to enter a file in which to save the key pair, as well as a passphrase. You can leave these blank if you want, but be aware that this will make your private key more vulnerable if it falls into the wrong hands.

Step 2: Copy the Public Key to the Remote Server

Once you have your key pair, you'll need to copy the public key to the remote server. This can be done with the following command, replacing username and remote_host with the appropriate values:

ssh-copy-id username@remote_host

You'll be prompted for your password on the remote server. After you enter it, your public key will be added to the remote server's authorized_keys file.

Step 3: Test Your Passwordless SSH Connection

Now that your public key is on the remote server, you should be able to SSH into it without being prompted for a password. Try it out with the following command:

ssh username@remote_host

If everything was successful, you should now be logged into the remote server without having to enter a password.

Conclusion

And that's it! With ssh-copy-id, you can now SSH into your remote servers without having to remember or type your password every time.