LoginSignup
20
16

More than 5 years have passed since last update.

~/.ssh/configの設定(自分用メモ)

Posted at

概要

.ssh/config の設定内容に関する資料。

.ssh/configとは?

.ssh/configとは、ssh経由でのリモートサーバーの接続する際に利用される設定ファイルです。

記載するメリット

sshコマンドでサーバにログインする際のオプション等を省略出来る。
例えば一般的な接続コマンド↓

ssh ユーザー名@hoge.example.com

ユーザー名とホスト名を指定する方法、これはかなり単純な例なので、メリットがあまりないが、下記のようにポート番号がデフォルト(22)では無い場合、公開鍵認証で、鍵がデフォルトの名前ではなかったりした場合、コマンドが複雑になってしまう。

# ポート名を指定する場合
ssh ユーザー名@ホスト名 -p ポート番号

# 公開鍵認証の場合
ssh ユーザー名@ホスト名 -i ~/.ssh/鍵の名前

# ポート名&公開鍵認証の場合
ssh ユーザー名@ホスト名 -i ~/.ssh/鍵の名前 -p ポート番号

設定例

~/.ssh/config
Host *
ServerAliveInterval 60
    ForwardAgent yes
    ForwardX11Trusted yes
    ControlMaster auto
    ControlPath /Users/nishimoto-keita/.ssh/.connect/%r@%h:%p
    ControlPersist 10

Host sshgw
    Hostname 206.209.100.50
    User nishimoto-keita

Host stg
    HostName 206.209.142.22
    User nishimoto-keita
    ProxyCommand ssh -W %h:%p sshgw

Host aws
    HostName 50.11.14.160
    Port 22
    User ec2-user
    IdentityFile ~/.ssh/ec2_keys.pem

例えば、206.209.142.22環境にSSHを行う為には、最初に踏む台サーバの206.209.100.50を経由して接続を行う必要があるのだがこちらの設定を行っておけば以下のコマンドで接続出来る。

ssh stg

各項目毎にそれぞれ意味があるのだが、そのあたりは時間がある時にでも追記します。

20
16
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
20
16