您的位置:首页 > 运维架构 > Linux

SSH不输入密码连接远程Linux主机

2014-06-26 14:57 495 查看
原文地址:http://blog.chinaunix.net/uid-25266990-id-2600515.html

1) 在本地主机生成密钥对

ssh-keygen -t rsa

这个命令生成一个密钥对:id_rsa(私钥文件)和id_rsa.pub(公钥文件)。默认被保存在~/.ssh/目录下。

2) 将公钥添加到远程主机的 authorized_keys 文件中

将文件上传到远程主机中

scp ~/.ssh/id_rsa.pub root@192.168.17.113:/root/

SSH到登陆到远程主机192.168.17.113,将公钥追加到 authorized_keys 文件中

cat /root/id_rsa.pub >> /root/.ssh/authorized_keys

或直接运行命令:

cat ~/.ssh/id_dsa.pub|ssh root@192.168.17.113 'sh -c "cat - >>~/.ssh/authorized_keys"'

3) 重启 open-ssh 服务

/etc/init.d/ssh restart

4) 本地测试

ssh root@192.168.17.113

scp /root/.ssh/id_rsa.pub root@192.168.17.113:/root/

同样,使用rsync同步文件内容也是如此:

rsync -avH --delete /root/install.log root@192.168.17.113:/root/

(--delete远程文件将被删除)

呵呵,不用输入密码了:)
== 附录 ==

/etc/ssd/sshd_config 几个关键配置点

PermitRootLogin yes

PasswordAuthentication yes

# AuthorizedKeysFile .ssh/authorized_keys # 这个地方尽量使用默认,gentoo 下 ~/.ssh/authorized_keys

如果是多台服务器,方法都一样!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: