3

一个简单的SSH Pass脚本

 2 years ago
source link: https://qcute.github.io/posts/shell/ssh-pass/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
#!/usr/bin/env bash
# sshpass - use command line password with ssh
# inspire by https://github.com/huan/sshpass.sh
# ref to https://www.exratione.com/2014/08/bash-script-ssh-automation-without-a-password-prompt/
# the origin sshpass pass passphrase by pipe, but Symfony Process pipe need --enable-sigchild
# examples:
# sshpass <ssh or key passphrase> ssh <ssh options>
# sshpass <ssh or key passphrase> scp <scp options>
# sshpass <ssh or key passphrase> rsync <rsync options>
# sshpass <ssh or key passphrase> git <git options>
# sshpass <ssh or key passphrase> svn <svn options>

if [[ -n "${SSH_ASKPASS_PASSWORD}" ]];then
    cat <<< "${SSH_ASKPASS_PASSWORD}"
else
    export SSH_ASKPASS="$0"
    export SSH_ASKPASS_PASSWORD="$1"
    export DISPLAY=:0
    shift
    setsid "$@" </dev/null
fi
sshpass your_passphrase ssh name@host "echo hello world"

适用于SSH/SCP/RSync/Git/SVN等使用SSH的命令


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK