下面这个方法带来的后果是,多机之间进行互通时,authorized_keys被不断的覆盖,以至于前面配通的又不通了。
****************************************************
[root@localhost ~]# ssh-keygen -t rsa
然后一路回车
[root@localhost ~]# chmod 755 ~/.ssh
[root@localhost ~]# scp ~/.ssh/id_rsa.pub serverIP:/root/.ssh/authorized_keys
会提醒你输入server的root的密码,输入密码。
这样就ok了。
以后想登录server
只要在root下
#ssh serverip
不用输入密码即可直接进入server下。
***************************************************
真正可用的方法如下:
多机之间的ssh无密码互通,可以先在各节点上公钥,然后将各节点公钥合并为一个公钥,再分发到各节点上即可。(如下代码没有测试过,/opt/app/sshpub/是共享的NFS目录)
Node=(c2401 c2402 c2403 c2405 c2408)
for((i=0;i<5;i++))
do
ssh ${Node[i]} -f
ssh-keygen -t rsa //This command will produce public key and private key in the fixed directory ~/.ssh/, regardless where the command is executed.
ssh ${Node[i]} -f
chmod 755 ~/.ssh
ssh ${Node[i]} -f
cat ~/.ssh/id_rsa.pub >> /opt/app/sshpub/authorized_keys
done
Node=(c2402 c2403 c2405 c2408)
for((i=0;i<4;i++))
do
ssh ${Node[i]}
chmod 755 ~/.ssh
cp /opt/app/sshpub/authorized_keys ~/.ssh/authorized_keys
done
上面这段程序有点愚蠢
Node=(c2401 c2402 c2403 c2405 c2408)
for((i=0;i<5;i++))
do
//This command ssh-keygen -t rsa will produce public key and private key in the fixed directory ~/.ssh/, regardless where the command is executed.
ssh ${Node[i]} ‘ssh-keygen -t rsa; chmod 755 ~/.ssh;cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys’
done
对于其他用户,为了省事也可以直接把这个文件拷到对应的 ~/.ssh,别忘了chmod 755 ~/.ssh
这个方法似乎不行,我把这个文件离得所有root替换为wgzhang后还是不行
问题2:
在用上面这个脚本时候,发现还是有问题,对照一个已经做好的系统,发现authorized的属性是rw-r-r,于是把chmod 644 authorized_keys后,zhxue用户才ssh无密码互通。