LoginSignup
0
0

More than 3 years have passed since last update.

踏み台で sudo -u しているsshでの ssh_config

Last updated at Posted at 2020-12-24

やりたいこと

今回想定する接続の流れ

手元(local/mac) -> 踏み台(bastion_host/linux) -> 最終ターゲット(target_host/linux)

以下のようなワンライナーを.ssh/configで表現したい

ssh -t foo@bastion_host -p 22 sudo -u bar ssh target_host

制約として、 bastion_host に置いてある target_host の鍵を localにもってこれないとする。

この制約があると、すんなり .ssh/config には記載できない...。

環境

  • local
    • OpenSSH_7.9p1, LibreSSL 2.7.3

どうするか

  • helper scriptでなんとかする(参考)
    • .ssh/config に設定をまとめたいがそれはできない
  • RemoteCommand に記述する(今回やってみる)
    • .ssh/config に設定をまとめられる

RemoteCommand に記述する

具体的には、.ssh/config に以下のように記載する

Host foobar
  HostName bastion_host
  RequestTTY force
  User foo
  Port 22
  RemoteCommand sudo -u bar ssh -t target_host

そして以下のようにsshすればOK

$ ssh foobar

RemoteCommand とはなにか

  • OpenSSHの7.6で入った比較的新しい機能(参考)
  • サーバーへの接続に成功した後、リモートマシンで実行するコマンドを指定するものです。(参考)
0
0
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
0
0