LoginSignup
176
181

More than 5 years have passed since last update.

.ssh/configで設定すると接続が楽になる方法

Posted at

puttyよりcygwin派です。
cygwinでsshする時に、.ssh/configに書くと便利な設定を記載。

1.接続が閉じられるのを防ぐ

アクセス先のサーバーで何も操作しないと、一定時間で接続が切れてしまうことがあります。
これを防ぐには

ServerAliveInterval 30

を追加します。
自動で30秒に1回サーバーに通信し、接続が切れるのを防ぎます。
※秒数は変更可能。

2.別名で接続

接続先サーバー名にホスト名がなかったり、ドメインが長い、分かりづらい場合に設定します。

[設定前の接続方法]

ssh 123.567.890.001

<設定>

Host sample1
    HostName 123.567.890.001

[設定後の接続方法]

ssh sample1

(以下の全ての方法でも同じ)

3.別名で接続+ポート指定

[設定前の接続方法]

ssh -p10123 123.567.890.001

<設定>

Host sample1
    HostName 123.567.890.001
    Port 10123

4.別のアカウントで接続

通常使用しているアカウントとは別アカウントで接続。
[設定前の接続方法]

ssh -i ~/.ssh/sample_id_rsa abc@123.567.890.001

<設定>

Host sample1
    HostName 123.567.890.001
    User abc
    IdentityFile ~/.ssh/sample_id_rsa

5.多段接続

[設定前の接続方法]

ssh 111.111.111.111
ssh 222.222.222.222

<設定>

Host sample1
    HostName 222.222.222.222
    ProxyCommand ssh -W %h:%p 111.111.111.111
176
181
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
176
181