SSH Config

SSH Config File Structure and Patterns

The SSH Config File takes the following structure:

Host hostname1
    SSH_OPTION value
    SSH_OPTION value

Host hostname2
    SSH_OPTION value

Host *
    SSH_OPTION value

Each stanza starts with the Host directive and contains specific SSH options used when establishing a connection with the remote SSH server.

The SSH config file is also read by other programs such as scp , sftp , and rsync .

The Host directive can contain one pattern or a whitespace-separated list of patterns. Each pattern can contain zero or more non-whitespace character or one of the following pattern specifiers:

  • * - Matches zero or more characters. For example, Host * matches all hosts, while 192.168.0.* matches hosts in the 192.168.0.0/24 subnet.
  • ? - Matches exactly one character. The pattern, Host 10.10.0.? matches all hosts in 10.10.0.[0-9] range.
  • ! - When used at the start of a pattern, it negates the match. For example, Host 10.10.0.* !10.10.0.5 matches any host in the 10.10.0.0/24 subnet except 10.10.0.5

SSH Config File Example

Host oci-test-instance-phoenix
    HostName 192.168.1.10
    User mimigonz
    Port 20
    IdentityFile ~/.ssh/targaryen.key

Using ProxyCommands

If you need to ssh into a host via a bastion, this is how you specify it

Host bastion
	user bastionuser
	hostname 192.168.10.100
	IdentityFile ~/.ssh/bastion_key
	
Host cloud-instance
	user instanceuser
	hostname 10.1.23.146
	IdentityFile ~/.ssh/cloudinstance_key

Then you can use ssh -J bastion cloud-instance

Or you could also specify the proxy jump in the ssh config

Host bastion
	user bastionuser
	hostname 192.168.10.100
	proxyjump cloud-instance
	IdentityFile ~/.ssh/bastion_key
	
	
Host cloud-instance
	user instanceuser
	hostname 10.1.23.146
	IdentityFile ~/.ssh/cloudinstance_key

Using OCI Bastion 4.0

Host bm-* 
    User clouduser

Host jumpbox
    Hostname <cloud-bastion-ocid>-<jumpbox ip>
    ProxyJump bastion
	
Host bastion
    Hostname <overlay-bastion-endpoint>
	

Example:

Host bm-* 
    User mimigonz

Host bm-amsterdam-jumpbox bm-amsterdam-jbx bm-ams-jbx
    Hostname ocid1.bastion.oc1.eu-amsterdam-1.amaaaaaapvbknfyaqyos22ydj7nawvdjm7q7qfxd2vwpwt4auxay7btxwnqa-172.16.90.83
    ProxyJump bm-ams
	
Host bm-amsterdam bm-ams
    Hostname overlay-host.bastion.eu-amsterdam-1.oci.oracleiaas.com