23
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SSH : 踏み台サーバを経由してSSH接続する設定ファイルの書き方いろいろ

23
Posted at

ローカルユーザはニックネームで作っていたが踏み台と接続先のサーバでは本名でユーザが作られていて、どう設定ファイルを書けば繋がるのか試してみた

前提条件

ローカルのユーザ名 : taiga
踏み台のユーザ名 : yamada-taro

踏み台サーバのIPアドレス : XXX.XXX.XXX.XXX
port : AA
踏み台を経由して接続するサーバのIPアドレス : YYY.YYY.YYY.YYY
port : AA

秘密鍵(ローカル) : ~/.ssh/id_rsa
秘密鍵(踏み台) : ~/.ssh/id_rsa

サーバの接続イメージ

接続イメージ図

ssh hoge と入力してlocalから接続先につなげる場合のssh/configの設定

パターン1

~/.ssh/config
host hoge1
    user yamada-taro
    hostname YYY.YYY.YYY.YYY
    port AA
    identityfile ~/.ssh/id_rsa
    ProxyCommand ssh -i ~/.ssh/id_rsa XXX.XXX.XXX.XXX nc %h %p

パターン2

~/.ssh/config
host hoge2
    user yamada-taro
    hostname YYY.YYY.YYY.YYY
    port AA
    ProxyCommand ssh -i ~/.ssh/id_rsa XXX.XXX.XXX.XXX -l yamada-taro nc %h %p

パターン3

~/.ssh/config
host fumidai
    user yamada-taro
    hostname XXX.XXX.XXX.XXX
    Identityfile ~/.ssh/id_rsa
    port AA

host hoge3
    user yamada-taro
    hostname YYY.YYY.YYY.YYY
    port AA
    ProxyCommand ssh fumidai nc %h %p

繋がらないパターン

~/.ssh/config
host hogex
    user yamada-taro
    hostname YYY.YYY.YYY.YYY
    port AA
    ProxyCommand ssh -i ~/.ssh/id_rsa XXX.XXX.XXX.XXX nc %h %p

※「yamada-taro」ではなく「taiga」として接続しようとするので繋がらない

23
22
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
23
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?