Skip to content

Instantly share code, notes, and snippets.

@aont
Created April 12, 2013 13:11
Show Gist options
  • Select an option

  • Save aont/5371891 to your computer and use it in GitHub Desktop.

Select an option

Save aont/5371891 to your computer and use it in GitHub Desktop.
シェルスクリプト上でのSSH接続の再利用 ・パスワード入力は最初だけ ・鍵を作ってない人でも使えるはず(ssh-agentの代わりになる)
#!/bin/sh
echo start ssh session 1>&2
ssh -T -N -f -oControlMaster=yes -oControlPath=~/.ssh/master.$$.%r@%h:%p hoge.com
echo command execution on remote 1>&2
ssh -oControlMaster=no -oControlPath=~/.ssh/master.$$.%r@%h:%p hoge.com echo echo on remote
echo close connection 1>&2
ssh -O exit -oControlMaster=no -oControlPath=~/.ssh/master.$$.%r@%h:%p hoge.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment