bash 以 root 身份无密码 ssh 到远程系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15351491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:49:23  来源:igfitidea点击:

passwordless ssh to remote system as root

linuxbashssh

提问by cached

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 ?

我需要 ssh(以 root 身份)到远程服务器并执行一些 root 级别的操作。我将从我没有 root 权限的本地服务器进行 sshing。鉴于此选项,是否可以使用 (rsa) 密钥对远程系统执行无密码 ssh ?

Local and remote servers run linux.

本地和远程服务器运行 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.

顺便说一句,我在本地服务器上生成了密钥(ssh-keygen -t rsa)。将公钥复制到远程服务器的 .ssh/authorized_keys 文件。但是它仍然不断提示输入密码。如果本地和远程用户名(非 root)匹配,则相同的设置可以正常工作。

回答by Kun Ling

1 check that your /etc/ssh/sshd_config file have "PermitRootLogin yes".

1 检查您的 /etc/ssh/sshd_config 文件是否有“PermitRootLogin yes”。

2 Store the following Shell code into nopasswd.sh:

2 将以下 Shell 代码存储到 nopasswd.sh 中:

#!/bin/sh

scp ~/.ssh/id_dsa.pub  @:~/
ssh @ "cat ~/id_dsa.pub  >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys; exit"

3 Use it by these steps:

3 按以下步骤使用:

$ssh-keygen -t dsa
$ ./nopasswd.sh root REMOTE_HOST

回答by perreal

In ~/.ssh/config:

在 ~/.ssh/config 中:

Host rootRemoteSystem
HostName RemoteSystem
User root

Then:

然后:

ssh-copy-id rootRemoteSystem

Then you can do:

然后你可以这样做:

ssh rootRemoteSystem

回答by that other guy

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.

是的。SSH 不会在不同系统上的帐户名之间建立连接,因此如果您有有效的密钥对,您可以以非 root 身份通过 ssh 连接到 root。