0
2

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/config を分けよう

0
Last updated at Posted at 2020-05-28

はじめに

SSH通信していると、鍵の管理がわからなくなってきますよね。特にまだ使う鍵なのか、どれを使っているのかとかですね。なのでフォルダで管理できるようにしていきましょう。

参考リンク

・Mac で .ssh/config ファイルを include で分割して管理
・Includeキーワードでssh_configを分割できるようになった件
・[Sierra] macos Sierra に更新してから、毎回パスフレーズを聞かれてくることに対する対策 [ssh]
・ターミナルからssh接続を試みるとエラーが発生

結果

フォルダは以下のようになりました。

.ssh
├── conf.d
│   ├── env1
│   │   ├── config
│   │   ├── id_rsa
│   │   └── id_rsa.pub
│   └── env2
│       ├── config
│       ├── id_rsa
│       └── id_rsa.pub
├── config
└── known_hosts

各ファイルに記述しているものを載せていきます。

~/.ssh/config
Include ~/.ssh/conf.d/**/config

Host *
  ServerAliveInterval 300
  AddKeysToAgent yes
  UseKeychain yes

また面倒ですが、各configの権限も設定してあげないとエラーが出るので注意してください。

$ chmod 700 config

各フォルダのconfig例

~/.ssh/conf.d/env1/config
Host env1
  User centos # 入る先のユーザー名
  Port 22
  HostName ホストのIP
  identityFile /Users/username/.ssh/conf.d/env1/id_rsa 
  TCPKeepAlive yes
  Identitiesonly yes
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?