1. 程式人生 > >ssh免密腳本

ssh免密腳本

pre ssh免密 bin author chmod echo -s ssh then

#!/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 [email protected]$server \`$cmd\` fi

ssh免密腳本