分享

shell 安装集群的免密登陆报错/usr/bin/ssh-copy-id: ERROR: No identities found ...

pandatyut 发表于 2016-8-11 22:54:14 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 14601
安装集群的时候要进行免密登陆,不想每台机器都手动人工操作,从网上找了一段shell脚本,如下:#!/bin/bash
# for self configure
wd=.tmp_ssh
#mkdir -p $wd
echo "mkdir success"
hosts=(`sed -n '3,$p' /etc/hosts | awk '{print $1}'`)
for i in "${hosts[@]}"
do
  script=$(cat << \EOF
  ssh-keygen -t rsa <<eof
eof
EOF
)
exe='bash << EOF
'"$script"'
EOF'
echo =======$i=======
ssh -o StrictHostKeyChecking=no $i "$exe"
# eval `ssh-agent -s`
# ssh-add -L
ssh-copy-id -i ~/.ssh/id_rsa.pub $i
scp $i:~/.ssh/id_rsa.pub $wd/id_rsa.pub_$i
done
cat $wd/id_rsa.pub_*  > $wd/authorized_keys
chmod 600 $wd/authorized_keys
for i in "${hosts[@]}"
do
   scp $wd/authorized_keys $i:~/.ssh/
   scp ~/.ssh/known_hosts    $i:~/.ssh/
done
rm -rf $wd
echo "ssh finished!"
以root运行之后结果如下:报/usr/bin/ssh-copy-id: ERROR: No identities found错误,不知道什么原因,求高手解答

mkdir success
=======192.168.2.185=======
root@192.168.2.185's password:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /usr/bin/ssh-copy-id: ERROR: No identities found
root@192.168.2.185's password:
scp: /root/.ssh/id_rsa.pub: No such file or directory
=======192.168.2.186=======
root@192.168.2.186's password:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /usr/bin/ssh-copy-id: ERROR: No identities found
root@192.168.2.186's password:
scp: /root/.ssh/id_rsa.pub: No such file or directory
=======192.168.2.187=======
root@192.168.2.187's password:
Unable to get valid context for root
/usr/bin/ssh-copy-id: ERROR: No identities found
root@192.168.2.187's password:
Unable to get valid context for root
./ssh.sh: line 24: .tmp_ssh/authorized_keys: No such file or directory
chmod: cannot access `.tmp_ssh/authorized_keys': No such file or directory
root@192.168.2.185's password:
.tmp_ssh/authorized_keys: No such file or directory
root@192.168.2.185's password:
known_hosts                                           100% 1201     1.2KB/s   00:00   
root@192.168.2.186's password:
.tmp_ssh/authorized_keys: No such file or directory
root@192.168.2.186's password:
known_hosts                                           100% 1201     1.2KB/s   00:00   
root@192.168.2.187's password:
Unable to get valid context for root
root@192.168.2.187's password:
Unable to get valid context for root
ssh finished!


已有(2)人评论

跳转到指定楼层
desehawk 发表于 2016-8-12 11:19:12
应该是路径搞错了吧
回复

使用道具 举报

qcbb001 发表于 2016-8-12 16:30:33
最好不使用root用户,这个脚本默认是应该是非root用户。
id_rsa楼主保存在了下面路径
(/root/.ssh/id_rsa)
复制的时候,是用的下面路径
~/.ssh/id_rsa.pub

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条