You can use ssh-keygen to do this
ssh-keygen -t rsa -b 2048
answer the questions or accept the defaults then provide a passphrase for the private key.
Now send the pubic key (id_rsa.pub) to the remote host as they request.
Put the private key in ~/.ssh/id_rsa for the user that you want to access the remote host. Ensure the perms on the .ssh directory are 700 and ~/.ssh/id_rsa is 600.
You should be good to go.
useradd testuser
su - testuser
ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/testuser/.ssh/id_rsa):
Created directory '/home/testuser/.ssh'.
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/testuser/.ssh/id_rsa.
Your public key has been saved in /home/testuser/.ssh/id_rsa.pub.
The key fingerprint is:
81:dc:8d:19:f1:32:39:67:89:47:88:dc:a6:8a:3d:40 [email protected]
Send the id_rsa.pub
to the remote host where is should be put in the user's ~/.ssh/authorized_keys
with permissions 600
or 644
at most.
ssh-copy-id
, which will copy your public key and place it in the target user@machine's authorized_keys file in the right way.man ssh-copy-id
for more details. You will obviously need to generate the keys first, before runningssh-copy-id
, as per the instructions in the Answers.