0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

.sshのconfigを分割して管理

Posted at

背景

.ssh/config ファイルが長くなってきたので、分割して管理する

フォルダ構成

[~/.ssh]
$ tree
.
├── conf.d
│   ├── config
│   └── server1.conf(自分で作成⭐︎)
├── config
├── id_rsa
├── id_rsa.pem
├── id_rsa.pub
├── ssh
└── sshKey

設定ファイル

ssh server1で接続できるように以下を追加

server1.conf
Host server1
    HostName {IPアドレス}
    User {ユーザ指定}
    IdentityFile ~/.ssh/id_rsa
    Port 22
    TCPKeepAlive yes

ファイルの結合

  • .zshrcにsshの設定を結合する用のコマンドエイリアスを作成

.zshrc
alias ssh-config-update="cat ~/.ssh/conf.d/config ~/.ssh/conf.d/*.conf > ~/.ssh/config"
  • .zshrcを再読み込みして、~/.ssh/configを更新

$ source ~/.zshrc
$ ssh-config-update
  • 今後追加したら以下を実行

$ ssh-config-update

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?