Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

How to SSH without username or password

πŸ“… 2016-Jan-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ssh ⬩ πŸ“š Archive

Problem

Normally when you SSH into a computer, you need to provide a username and it will prompt you for your password, like this:

$ ssh joe@server_machine
joe@server_machine's password:

By generating a public-private key pair on the local machine and sharing the public key with a remote machine, you can SSH to the remote machine without providing a login or being prompted for a password.

After this setup is done, you will operate like this:

$ ssh server_machine
$ That is it! You are logged in without login or password!

Solution

To set this up:

$ ssh-keygen -t ed25519 -C "your_email@example.com"

Here ed25519 is a key type. Other supported key types are rsa, dsa and ecdsa. It is recommended to use only ed25519 or rsa.

The above command generates a public key in ~/.ssh/id_ed25519.pub and its corresponding private key in ~/.ssh/id_25519 file. If you use a different key type, the file suffix would correspondingly be different.

$ ssh-copy-id remote_machine

If there is no ~/.ssh/authorized_keys file on the remote machine, this script will create it for you. If the file exists, your public key from local machine will be appended to the existing file.

If you have more than one public-private keys on your local machine, the ssh-copy-id might use the wrong one. In such cases, point out the right file using the -i option:

$ ssh-copy-id -i ~/.ssh/foobar_id_ed25519.pub remote_machine

Reference: Arabesque: Linux Crypto - SSH Keys

Tried with: Ubuntu 22.04


Β© 2023 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 Mastodon β€’ πŸ“§ Email