ssh 生成公钥

1.生成公钥
  ssh-keygen -t rsa
2.脚本
PRI_IP="$1"


if [ -d /root/.ssh ]
then
        rm -f /root/.ssh/*
else
        mkdir /root/.ssh
fi
chmod 700 /root/.ssh

/usr/bin/expect <<EOD
spawn ssh-keygen -t rsa
      for {} {1} {} {
            expect   {
                "*id_rsa):"  { send "\r" ; continue}
                "*rwrite (y/n)?" { send "y\r" ; continue }
                "*ssphrase):" { send "\r" ; continue }
                "*again:"     { send "\r" ; continue }
                -re . { exp_continue }
                eof { break }
            }
    }
EOD

/usr/bin/expect <<EOD
spawn scp /root/.ssh/id_rsa.pub ${PRI_IP}:/tmp
        for {} {1} {} {
             expect   {
             "*(yes/no)?" { send "yes\r" ; continue }
             "*assword:" { send "huawei\r" ; continue}
             -re . { exp_continue }
             eof { break }
     }
}
EOD

猜你喜欢

转载自junge8618.iteye.com/blog/962798