Install SSH Key In A Remote Linux Server
I’ve been setting up a new server and as always the first things to do is forbid root login using a password and install my SSH keys. Once again I had to Google for how to do this, so I thought I would write about it instead.
After creating a new SSH key, if you don’t already have one, you can install it into the target computer using the ssh-copy-id
command to install you certificate directly onto the machine.
There are many ways to use the ssh-copy-id
command:
nxad@desktop:~$ ssh-copy-id user@target.pc nxad@desktop:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@target.pc nxad@desktop:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub "user@target.pc -p 4242"
- Create the SSH keys:
nxad@desktop:~$ ssh-keygen
- (A) Install the public key:
nxad@desktop:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub username@target.pc
- (A) I If you do not have ssh-copy-id installed on your PC this will also work:
nxad@desktop:~$ ssh username@target.pc umask 077; mkdir .ssh nxad@desktop:~$ cat $HOME/.ssh/id_rsa.pub | ssh username@target.pc cat >> .ssh/authorized_keys