I have followed the process of creating the public and private keys so that I can login in to remote system without a password.

But I would like to login into the remote system as root user without password using SSH keys.

For example, vm2$ssh vm1@ would give me vm1$ prompt but I need ssh vm1@ to give me vm1#.

Is this possible?


Yes you can, though this is not a recommended setup.

To login as root user, you need to specify that you want the root user. The command would be

ssh root@

Of course, this only logs in, so in order to use your keys, you have to copy them:

ssh-copy-id -i ~/.ssh/id_rsa root@

You'll be prompted for password once. After that, you can SSH as the root user on with the first command.

| improve this answer | |
  • ssh-copy-id -i ~/.ssh/id_rsa root@ when I am giving this command and entering the password its showing Permission Denied, please try again – karra Dec 1 '18 at 12:12
  • @karra You'll need to enter the root password, or try something else (I'll add it later). – iBug Dec 1 '18 at 12:13
  • Sorry if its naive. The password for $sudo -s and the root password are same. right ? – karra Dec 1 '18 at 12:15
  • @karra yeah it is, but you need the root password of the remote machine – iBug Dec 1 '18 at 12:16
  • yes, I am entering the remote machine password. I have even checked on the remote machine – karra Dec 1 '18 at 12:17

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.