LoginSignup
4
4

More than 5 years have passed since last update.

手元端末の秘密鍵を使って踏み台経由で目的のサーバにssh(screen併用)

Posted at

やりたいこと

プレゼンテーション1.png

Windowsからputty/pageantでLinux踏み台経由で各サーバに行く場合、
screen/tmuxを踏み台で上げると便利ですが、ついでに手元のpageantの秘密鍵で
踏み台/各目的サーバに入れると便利ですね。
ついでにdetach/attachしても使えるといいです。今回はその辺りの要件を満たす方法を考えます。

設定内容

putty側設定

無題.png
まず、puttyのconnection->SSH->Authで「Allow agent forwarding」にチェックを入れます。
これだけで通常(screen等を使わない場合)は目的サーバへのログイン時でもpageantの秘密鍵を使うことが出来ます。

踏み台サーバ側設定

上のputty側設定でscreenでdetach/attachしなければログインはできるのですが、
作業途中に端末-踏み台間接続が切れたりした場合はログインできなくなりますので、
なんとかしたいところです。

そこでたとえば下記のようなaliasを設定します。(bash用)
bash:.bash_profile
alias ssh='SSH_AUTH_SOCK=`find /tmp/ssh-* -user ${USER} |grep agent| head -n1` ssh'
alias scp='SSH_AUTH_SOCK=`find /tmp/ssh-* -user ${USER} |grep agent| head -n1` scp'

この設定を入れることでscreen内で実行されたssh/scpがsshdの提供する仮想的なssh_agentを
見失わなくなり、detach/attachしても目的サーバにアクセスできるようになります。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4