HOWTO Create SSH Config file
HOWTO CREATE config FOR SSH PRE-DEFINED INFORMATION
- The config file is located in your ~/.ssh directory and hold specific
- variables for your ssh connections. One example is ssh into a non-standard
- port, or to always attempt to use -X for X11 forwarding.
- Adding info for encryption types and an example of howto automatically
- forward through computer B into C.
- The basic layout of the config file is as follows:
Host ANY_URL Port 22222 . ## note ignore the ., this is just for wiki formatting to keep the space without creating a new code block Host <IP_ANY_URL> Port 22222 . ## note ignore the ., this is just for wiki formatting to keep the space without creating a new code block Host * Protocol 2 ForwardAgent yes ForwardX11 yes ServeraliveInterval 30 ServerAliveCountMax 5 TCPKeepAlive yes . ## note ignore the ., this is just for wiki formatting to keep the space without creating a new code block Host Server_C User server_c_user ProxyCommand ssh -qax -W %h:%p URL_Server_B Ciphers aes256-ctr,aes256-cbc
- The first "Host" is the fully qualified domain name ie: google.com. For this connection
we are defining port 22222 as the standard port for this connection. Now instead of typing:
[user@server ~]$ ssh -p 22222 user@ANY_URL
- You can now just type:
[user@server ~]$ ssh user@ANY_URL
- This is real handy for scp and other options like ssh-copy-id that can be a royal pain for
- The second "Host" is the IP address of the fully qualified domain name of the first "Host".
Always better safe then sorry. It is not required, but if for some reason your DNS is not working 100%, this will be a way around said issue. Great in LANs as well as WWW connections.
- The third "Host" in the above example is for all connections. We are stating use protocol vs. 2
over 1. Always attempt to use X11 forwarding.
- The fourth "Host" in the above example is for forwarding your ssh connection from the outside facing computer into a 2nd system that is NOT directly accessible via a straight ssh from the WWW. This is used like the following...
[user@server_A ~]$ ssh Server_C Last login: Sun Jul 27 15:36:26 2014 from user_server_A [server_C_user@Server_C ~]$
- Once you have created this file you will need to verify the permissions and that it is locaed
in the correct directory.
[user@server ~]$ ls -laF .ssh total 48 drwx------. 2 user user 4096 Mar 14 15:23 ./ drwx------. 17 user user 4096 Mar 29 19:40 ../ -rw-------. 1 user user 4466 Mar 12 10:30 authorized_keys -rw-r--r--. 1 user user 175 Jan 5 12:23 config -r--------. 1 user user 3243 Jan 5 12:14 id_rsa -rw-r--r--. 1 user user 741 Jan 5 12:14 id_rsa.pub -rw-r--r--. 1 user user 1447 Mar 14 15:23 known_hosts
- Without these permissions your config file will fail. This will work in both Linux and OSx.