passwordless ssh to remote system as root [closed]

2019-09-08 17:50发布

问题:

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:

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


回答2:

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.



回答3:

In ~/.ssh/config:

Host rootRemoteSystem
HostName RemoteSystem
User root

Then:

ssh-copy-id rootRemoteSystem

Then you can do:

ssh rootRemoteSystem


标签: linux bash ssh