User Tools

Site Tools


howto:sshkey

Setting up Passwordless SSH-key

Ubuntu

ssh-keygen

You use the tool “ssh-keygen” to create your public-private key pair. Depending on what you need to do, there are many options available.

[user@host ~]$ ssh-keygen -t ed25519 -C "Add a Description to easily tell which machine this belongs to"
Generating public/private key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519): [Enter to leave default]
Enter passphrase (empty for no passphrase): [Enter to leave empty]
Enter same passphrase: [Enter to leave empty]

You should leave the default values above by simply hitting Enter three times. The private key is created in id_ed25519 and the matching public key is id_ed25519.pub. The id_ed25519 file name is what ssh will look for when attempting public-key authentication (unless specified differently in the /etc/ssh/ssh_config in the IdentityFile variable.

Distributing your public key

The *.pub file needs to be appended to the ~/.ssh/authorized_keys file to be recognized by ssh. This should be done on any remote hosts you wish to connect to using public-key authorization. Be sure each key starts on its own new line, since many users may need to connect to the machine and all be able to add their public keys to the authorized_keys file. The code below should do it:

# Your pub key's filename may differ depending on whether it was ed25519 (id_ed25519.pub), rsa (id_rsa.pub) or dsa (id_dsa.pub)
[user@localhost ~]$ scp ~/.ssh/id_ed25519.pub user@remotehost:/home/user/.ssh/my_id.pub
Enter password for user@remotehost:
[user@localhost ~]$ ssh user@remotehost
Enter Password
[user@remotehost ~]$ cd .ssh
[user@remotehost .ssh]$ cat my_id.pub >> authorized_keys
[user@remotehost .ssh]$ rm my_id.pub
howto/sshkey.txt · Last modified: 2025/05/12 21:51 by justip6