Setup an SSH Config File
If you use SSH even somewhat often, it would benefit you to setup a basic SSH config file. If you’re curious why, would you rather type something like this:
ssh -p 6851 firstname.lastname@example.org
Or just type:
I know what I’d rather do, so let’s get this working. I’m going to use nano editor because it’s user friendly.
Launch the Terminal and type the following:
You’ll probably have a blank config file and that’s fine, so here’s what we’ll add to it:
Here’s how this might look:
I keep things indented to make them easier to read but it’s not necessary. Once your server and login info is inputted, hit Control+O to save the file, then Control+X to quit out of nano.
Now you can just type the shorthand to connect to a server, such as ‘ssh osxd’ and the full hostname, port, and username will be included for you.
There are many more possibilities with SSH configs, if you want to check out more options just look at the manual page with “man ssh_config”
Check out some more command line tips while you’re at it.
This isn’t working for me. When I type ssh shortcutname I get
ssh: Could not resolve hostname shortcutname: nodename nor servname provided, or not known
I followed the instructions and nano reported that it had wrote four lines. Any ideas? Many thanks.
[…] Line – April 11th, 2011 – No Comments More fun with SSH! We showed you how to setup SSH config files and use tab completion for SSH aliases, but setting up bash aliases is even easier if you are […]
Or use LocalForward to forward a port on localhost to a machine on the remote network, for example RDP to a *cough*dos host:
LocalForward 3389 192.168.1.24:3389
rdesktop localhost:3389 will log you in to the *hatsjoe*dos machine on the remote LAN.
Sorry about the cold, folks.
If you login to host after host after host to get where you want you might want to add
to avoid getting logged out of the first connection when really wanting to stop ‘cu’ or ‘tip’ or ‘ssh’ on the remote machine.
[…] Line – April 6th, 2011 – No Comments Yesterday we showed you how to setup a basic SSH Config file, and here’s how to make that even more useful: enable tab completion for those SSH […]
why not simply use an alias?
I regularly type “box” which is an alias to “ssh myuser@ip”
A port can be added with :port# at the end… this alias survives all reboots.
I guess it is another way to do it…
That wouldn’t work e.g. with git on a non-standard port while tunneling over ssh.
quite handy for when you use ssh in a lab with servers that often change (dev/test)