码迷,mamicode.com
首页 > 其他好文 > 详细

ssh免密脚本

时间:2017-09-11 16:26:08      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:dir   class   echo   pre   cat   .sh   use   amp   log   

#!/bin/sh

if [ "$1"x = ""x ]; then
    echo "usage:/opt/bin/auto-ssh.sh user server"
else
    user=$1
    server=$2
    pubkey=`cat ~/.ssh/id_rsa.pub`
    if [ "$pubkey"x = ""x ]; then
       ssh-keygen
       pubkey=`cat ~/.ssh/id_rsa.pub`
    fi
    cmd="mkdir -p ~/.ssh && chmod 700 ~/.ssh && [ ! -e \‘~/.ssh/authorized_keys\‘ ] && touch ~/.ssh/authorized_keys&&echo \"$pubkey\" >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
    ssh $user@$server \`$cmd\`
fi

 

ssh免密脚本

标签:dir   class   echo   pre   cat   .sh   use   amp   log   

原文地址:http://www.cnblogs.com/wangmo/p/7505318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!