#!/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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-11-01
  • 2021-11-02
  • 2022-01-03
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-12-19
  • 2021-06-14
相关资源
相似解决方案