SSH 无密码登录

1、在主服务器master下生成密钥

$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

2、将密钥放在 ~/.ssh/authorized_keys

$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

3、对生成的文件authorized_keys授权

chmod 600 ~/.ssh/authorized_keys

4、编辑sshd_config文件,将下面三列#去掉

vim /etc/ssh/sshd_config

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile    .ssh/authorized_keys

5、重启sshd 服务(可省略)

service  sshd  restart

6、验证无验证登陆

ssh localhost

7  配置master无密钥登陆slave(以此可以配置master无密钥登陆slaveX)

注释:root为root用户,master为主机名

[root@slaver ~]# scp -r root@master :/root/.ssh/id_dsa.pub /root/.ssh/slaver.pub

[root@slaver ~]# cat ~/.ssh/slaver.pub >> ~/.ssh/authorized_keys

chmod 600~/.ssh/authorized_keys

vim /etc/ssh/sshd_config

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile    .ssh/authorized_keys

service sshd restart

相关推荐