Creating SSH keys to login into remote machines as root user

0

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@10.0.0.1 would give me vm1$ prompt but I need ssh vm1@10.0.0.1 to give me vm1#.

Is this possible?

karra

Posted 2018-12-01T11:50:38.670

Reputation: 11

Answers

0

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@10.0.0.1

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@10.0.0.1

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

iBug

Posted 2018-12-01T11:50:38.670

Reputation: 5 254

ssh-copy-id -i ~/.ssh/id_rsa root@10.0.0.1 when I am giving this command and entering the password its showing Permission Denied, please try again – karra – 2018-12-01T12:12:23.420

@karra You'll need to enter the root password, or try something else (I'll add it later). – iBug – 2018-12-01T12:13:23.987

Sorry if its naive. The password for $sudo -s and the root password are same. right ? – karra – 2018-12-01T12:15:50.083

@karra yeah it is, but you need the root password of the remote machine – iBug – 2018-12-01T12:16:20.733

yes, I am entering the remote machine password. I have even checked on the remote machine – karra – 2018-12-01T12:17:22.257

@karra Then it's possible that the remote machine has disabled root login. Check /etc/ssh/sshd_config on the remote machine and look for PermitRootLogin. Change it to yes to add your key, and change it to prohibit-password after you're done. – iBug – 2018-12-01T12:18:43.977

Info: 1 key(s) remain to be installed and I am getting permission denied. Initially, I have changed it to yes and then tried. StrictModes is this related to this configuration ? – karra – 2018-12-01T12:37:19.303