I need to ssh (as root) to a remote server and perform some root level operations. I will be sshing from a local server where I don't have root privileges. Given this option, is it possible to perform passwordless ssh to remote system using (rsa) keys ?
Local and remote servers run linux.
BTW, I generated keys (ssh-keygen -t rsa) on the local server. Copied the public key to remote server's .ssh/authorized_keys file. However it still keeps prompting for password. The same setup works fine, if the local and remote username (non-root) matches.
1 check that your /etc/ssh/sshd_config file have "PermitRootLogin yes".
2 Store the following Shell code into nopasswd.sh:
#!/bin/sh
scp ~/.ssh/id_dsa.pub $1@$2:~/
ssh $1@$2 "cat ~/id_dsa.pub >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys; exit"
3 Use it by these steps:
$ssh-keygen -t dsa
$ ./nopasswd.sh root REMOTE_HOST
Yes. SSH does not make a connection between account names on different systems, so you can ssh as non-root to root if you have a valid key pair.
In ~/.ssh/config:
Host rootRemoteSystem
HostName RemoteSystem
User root
Then:
ssh-copy-id rootRemoteSystem
Then you can do:
ssh rootRemoteSystem