Since our server admin has left it would be a good time to change the login key for root? How do we go about this?


You will need to generate a new keypair, add the generated public key to root's authorized_keys file and remove the current public key from the authorized_keys file too. The authorized_keys file should be found in root's $HOME/.ssh directory.

The format of the $HOME/.ssh/authorized_keys is one key per line, if you have more than one key, you will have to identify the one currently in use to remove it.

Generate a new key with the ssh_keygen command

ssh-keygen -t rsa -b 2048 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/iain/.ssh/id_rsa): /home/iain/.ssh/tmp/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/iain/.ssh/tmp/id_rsa.
Your public key has been saved in /home/iain/.ssh/tmp/id_rsa.pub.
The key fingerprint is:
f6:96:81:f4:15:70:d7:df:3f:dc:5e:0e:85:b1:2e:83 iain@test.lan

Now add the new public key (id_rsa.pub) to root's authorized_keys file, test that you can log in correctly with it and then remove the old key.

You may want to consider disabling roots ability to log in directly to your server and have people who need root access log in using their own credentials and then use sudo to perform admin tasks.

| improve this answer | |

Remove his public key and add your public key.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.