ssh免密码登录



#!/bin/bash REMOTE_IP_ARRAY="10.10.1.xx" REMOTE_PORT=22 REMOTE_USER=root RSA_FILE=~/.ssh/id_rsa.pub cd ~/.ssh if [ -f $RSA_FILE ]; then echo "rsa file exists!" else echo "rsa file not exist! now begin gen it" ssh-keygen -t rsa fi ip=$REMOTE_IP_ARRAY #ssh-keygen -t rsa #for ip in $REMOTE_IP_ARRAY #do REMOTE_IP=$ip ssh -p$REMOTE_PORT ${REMOTE_USER}@${REMOTE_IP} "mkdir .ssh;chmod 700 .ssh;touch ~/.ssh/authorized_keys;chmod 600 ~/.ssh/authorized_keys" ssh-copy-id -p$REMOTE_PORT -i ${RSA_FILE} ${REMOTE_USER}@${REMOTE_IP}

  

执行上面SHELL出现错误

-bash: ssh-copy-id: command not found

 

那么可以用这个方法:


ssh-keygen -t rsa


cat ~/.ssh/id_rsa.pub|ssh root@10.10.1.xx  'cat >> .ssh/authorized_keys'

 

posted on 2017-11-30 18:03  陈国利  阅读(153)  评论(0编辑  收藏  举报