SSH ?

, IP,,

Solutions

~/.ssh/config (Recommended)Recommended

# ~/.ssh/config # === ===
Host * ServerAliveInterval 60 ServerAliveCountMax 3 AddKeysToAgent yes ControlMaster auto ControlPath ~/.ssh/sockets/%r@%h-%p ControlPersist 600 # === ===
Host prod-web HostName 10.0.1.10 User deploy IdentityFile ~/.ssh/prod_key ProxyJump bastion-prod Host prod-db HostName 10.0.1.20 User dba IdentityFile ~/.ssh/prod_key ProxyJump bastion-prod Host bastion-prod HostName bastion.prod.example.com User jump IdentityFile ~/.ssh/prod_key # === ===
Host test-* User admin IdentityFile ~/.ssh/test_key ProxyJump bastion-test Host test-web HostName 172.16.0.10 Host test-api HostName 172.16.0.11 Host bastion-test HostName bastion.test.example.com User jump IdentityFile ~/.ssh/test_key

config, Host. Host test-*. ControlMaster.

: 5, and

/

# ssh-keygen -t ed25519 -f ~/.ssh/prod_key -C "prod@company"
ssh-keygen -t ed25519 -f ~/.ssh/test_key -C "test@company"
ssh-keygen -t ed25519 -f ~/.ssh/github_key -C "dev@company" # config Host Host prod-* IdentityFile ~/.ssh/prod_key Host test-* IdentityFile ~/.ssh/test_key Host github.com IdentityFile ~/.ssh/github_key User git

,. and.

:,

Include

# ~/.ssh/config()
Include config.d/* Host * ServerAliveInterval 60 AddKeysToAgent yes # ~/.ssh/config.d/work()
Host work-* User deploy IdentityFile ~/.ssh/work_key Host work-prod HostName prod.work.com # ~/.ssh/config.d/personal()
Host personal-* User admin IdentityFile ~/.ssh/personal_key Host personal-blog HostName blog.example.com

OpenSSH 7.3+ Include,. /.

:, and

config 600, 700
Host, (Host *)
Include

Related Commands