Linux主机间双向免密码登陆
2012-12-01Linux撒加70258°c
A+ A-实验环境:
A 192.168.1.4 CentOS 6.3 登陆用户root hostname centos
B 192.168.1.5 Debian 6.0.5 登陆用户root hostname debian
这里默认操作都在/root下
在两台主机上分别修改/etc/ssh/sshd_config
sed -i 's:#AuthorizedKeysFile:AuthorizedKeysFile:g' /etc/ssh/sshd_config
修改完后重新reload下
在A上执行/etc/init.d/sshd reload
在B上执行/etc/init.d/ssh reload
A机器上执行如下指令:
rm -rf ~/.ssh
生成密钥
ssh-keygen -t rsa -P "" -f .ssh/id_rsa_centos
此时会在/root/.ssh/下生成两个文件:id_rsa_centos id_rsa_centos.pub
生成认证key
cat .ssh/id_rsa_centos.pub >> .ssh/authorized_keys
B机器上执行如下指令:
rm -rf ~/.ssh
生成密钥
ssh-keygen -t rsa -P "" -f .ssh/id_rsa_debian
此时会在/root/.ssh/下生成两个文件:id_rsa_debian id_rsa_debian.pub
将id_rsa_debian.pub拷贝至A机器
scp id_rsa_debian.pub root@192.168.1.4:/root/.ssh/
在A机器上执行cat .ssh/id_rsa_debian.pub >> .ssh/authorized_keys
将A机器上的authorized_keys拷贝至B机器/root/.ssh/下
scp .ssh/authorized_keys root@192.168.1.5:/root/.ssh/
在两台机器上分别检查.ssh目录和authorized_keys的权限,.ssh目录应该为700 authorized_keys文件应该为644
这样就可以让两台主机互相访问都不需要密码了