今天看了一位大神的ssh密钥分发脚本,其中他shell脚本里有一条ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub root@$ip,我执行后,报/usr/bin/ssh-copy-id: ERROR: No identities found,然后网上找了下-o StrictHostKeyChecking=no这项的含义,原来是强制不检查key,但ssh-copy-id我这里是不能使用的,所以最后我只能把-o StrictHostKeyChecking=no给去掉. 原来的脚本: #!/bin/sh read -p "输入远端服务器IP: " ip ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub root@$ip ssh root@$ip 'sed -i "s/^#RSAAuthentication\ yes/RSAAuthentication\ yes/g" /etc/ssh/sshd_config' ssh root@$ip 'sed -i "s/^#PubkeyAuthentication\ yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config' ssh root@$ip 'sed -i "s/^#PermitRootLogin\ yes/PermitRootLogin\ yes/g" /etc/ssh/sshd_config' ssh root@$ip 'service sshd restart' hostname=`ssh root@${ip} 'hostname'` echo "添加主机名和IP到本地/etc/hosts文件中" echo "$ip $hostname" >> /etc/hosts echo "远端主机主机名称为$hostname, 请查看 /etc/hosts 确保该主机名和IP添加到主机列表文件中" 修改后的脚本: #!/bin/sh read -p "输入远端服务器IP: " ip ssh-copy-id -i ~/.ssh/id_rsa.pub root@$ip ssh root@$ip 'sed -i "s/^#RSAAuthentication\ yes/RSAAuthentication\ yes/g" /etc/ssh/sshd_config' ssh root@$ip 'sed -i "s/^#PubkeyAuthentication\ yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config' ssh root@$ip 'sed -i "s/^#PermitRootLogin\ yes/PermitRootLogin\ yes/g" /etc/ssh/sshd_config' ssh root@$ip 'service sshd restart' hostname=`ssh root@${ip} 'hostname'` echo "添加主机名和IP到本地/etc/hosts文件中" echo "$ip $hostname" >> /etc/hosts echo "远端主机主机名称为$hostname, 请查看 /etc/hosts 确保该主机名和IP添加到主机列表文件中" 这样的话就不会再报/usr/bin/ssh-copy-id: ERROR: No identities found错误了. 如果大家要看大神的ssh密钥分发脚本,可以到这个地址:http://slaytanic.blog.51cto.com/2057708/1370007 (责任编辑:IT) |