{"id":865,"date":"2014-06-15T21:34:59","date_gmt":"2014-06-15T21:34:59","guid":{"rendered":"http:\/\/tech.avant.net\/q\/?p=865"},"modified":"2023-02-26T22:39:24","modified_gmt":"2023-02-26T22:39:24","slug":"getting-the-most-out-of-your-ssh-config","status":"publish","type":"post","link":"https:\/\/tech.avant.net\/q\/getting-the-most-out-of-your-ssh-config\/","title":{"rendered":"Getting the most out of your ssh config"},"content":{"rendered":"<p>I typically find myself with voluminous bashrc files filled with aliases and functions for connecting to specific hosts via ssh. I would like an easier way to manage the various ssh hosts, ports, and keys.<\/p>\n<p>I typically maintain an <a href=\"\/q\/ssh-agent-across-multiple-hosts\/\">ssh-agent across multiple hosts<\/a>, as well as various tunnels; <a href=\"\/q\/reverse-ssh-tunnel\/\">reverse tunnels<\/a>, and <a href=\"\/q\/chaining-ssh-tunnels\/\">chained tunnels<\/a> &#8212; but I would like to simplify my normal ssh commands using an ssh config.<\/p>\n<p>First, always remember to RTFM,<\/p>\n<pre class=\"sh_sh\">man ssh\n<\/pre>\n<p>This is an excellent starting point, the man page contains plenty of information on all the ins-and-outs of an ssh config.<\/p>\n<p>To get started, simply create a plaintext file &#8220;config&#8221; in your .ssh\/ directory.<\/p>\n<h2>Setting Defaults<\/h2>\n<p>$HOME\/.ssh\/config will be used by your ssh client and is able to set per-host defaults for username, port, identity-key, etc<\/p>\n<p>For example,<\/p>\n<pre class=\"sh_sh\"># $HOME\/.ssh\/config\nHost dev\n    HostName dev.tech.avant.net\n    Port 22000\n    User twarnock\n    ForwardAgent yes\n<\/pre>\n<p>On this particular host, I can now run<\/p>\n<pre class=\"sh_sh\">$ ssh dev\n<\/pre>\n<p>Which is much easier than &#8220;<em>ssh -A -p 22000 twarnock@dev.tech.avant.net<\/em>&#8221;<\/p>\n<p>You can also use wildcards, e.g.,<\/p>\n<pre class=\"sh_sh\">Host *amazonaws.com *ec2.nytimes.com *.dev.use1.nytimes.com\n    User root\n<\/pre>\n<p>which I find very useful for cases where usernames are different than my normal username.<\/p>\n<h2>Tunnels<\/h2>\n<p>Additionally, you can add tunneling information in your .ssh\/config, e.g.,<\/p>\n<pre class=\"sh_sh\">Host tunnel.tech.avant.net\n    HostName tech.avant.net\n    IdentityFile ~\/.ssh\/avant.key\n    LocalForward 8080 localhost:80\n    User twarnock\n<\/pre>\n<p>Even if you chose to use shell functions to manage tunnels, the use of an ssh config can help simplify things greatly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I typically find myself with voluminous bashrc files filled with aliases and functions for connecting to specific hosts via ssh. I would like an easier way to manage the various ssh hosts, ports, and keys. I typically maintain an ssh-agent across multiple hosts, as well as various tunnels; reverse tunnels, and chained tunnels &#8212; but [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,5],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/865"}],"collection":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":10,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":1221,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/865\/revisions\/1221"}],"wp:attachment":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/media?parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/categories?post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/tags?post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}