Use ssh_config To Simplify Your Life
When using multiple systems the indispensable tool is, as we all know, ssh. Using ssh you can login to other (remote) systems and work with them as if you were sitting in front of them. Even if some of your systems exist behind firewalls you can still get to them with ssh, but getting there can end up requiring a number of command line options and the more systems you have the more difficult it gets to remember them. However, you don't have to remember them, at least not more than once: you can just enter them into ssh's config file and be done with it.
For example, let's say that you have two "servers" that you connect to regularly, one at your house that's behind your firewall. Further, let's say that you use dyndns to make your home IP address known, and that you've got ssh listening on port 12022 rather than the default port 22 (and you've got your firewall forwarding that port to the server). So to connect you need to run:
$ ssh -p 12022 example.dyndns.org
The second system, let's say is local and you just connect with:
$ ssh 192.168.1.15
The second one is not too bad to type, but a name would be easier. You could put the name in your /etc/hosts file, or you could set up a local DNS server, but you can also solve this problem using ssh's config file.
To create an ssh config file execute the commands:
$ touch ~/.ssh/config
$ chmod 600 ~/.ssh/config
Now use your favorite text editor to edit the file and enter the following into it:
Host server1
HostName example.dyndns.org
Port 12022
Host server2
HostName 192.168.1.15
The Host option starts a new "section": all the options that follow apply to that host till a new "Host" option is seen. The "HostName" option specifies the "real" host name that ssh tries to connect to (otherwise the "Host" value is used). The "Port" is obviously the port that ssh tries to connect to, if you don't specify a port, the default port is used.
Now you can connect much more simply:
$ ssh server1
$ ssh server2
These are just a few of the options that you can set in ssh's config file. You can also, for example, specify that X11 forwarding be enabled. You can set up local and remote port forwarding (i.e. ssh's -L and -R command line options, respectively). Take a look at the man page (man ssh_config) for more information on the available options.
One of the added benefits of using ssh's config file is that programs like scp, rsync, and rdiff-backup automatically pick up these options also and work just as you'd expect (hope).
Mitch Frazier is an Associate Editor for Linux Journal.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Validate an E-Mail Address with PHP, the Right Way
- Technical Support Rep
- Senior Perl Developer
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Introduction to MapReduce with Hadoop on Linux
- Cari Uang
37 min 10 sec ago - user namespaces
3 hours 30 min ago - yea
3 hours 56 min ago - One advantage with VMs
6 hours 25 min ago - about info
6 hours 58 min ago - info
6 hours 59 min ago - info
7 hours 6 sec ago - info
7 hours 2 min ago - info
7 hours 3 min ago - abut info
7 hours 4 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Help. I made your changes to
Help. I made your changes to /etc/sshd_config, and now ssh doesn't work at all.
Hello...I started to
Hello...I started to implement a frontend to manage hosts via ssh_config.
https://sourceforge.net/projects/sshconf/
You can also use a GUI to configure ~/ssh/.config
A GUI with integrated help is also available to edit ~/ssh/.config. This GUI is provided by config-edit-ssh command.
On Debian, config-edit-ssh is provided by libconfig-model-openssh-perl package..
On other systems, you can download Config::Model::OpenSsh from CPAN to get config-edit-ssh.
For more details, see config-model-openssh on Freshmeat
Hope this helps
Can I use this with
Can I use this with public/private key pass-phrase? It asks me for a password instead of a pass-phrase when I use this. The config file looked like this:
Host *IdentityFile ~/.ssh/[user]
and now I added the shortcuts and it asks for a password. Even when I add the line
"IdentityFile ~/.ssh/[user]"to each host entry it still asks for password.Any one know a way around this? Otherwise, great shortcut, thanks!
Use ssh config to use proxy server
If you are allow you to ssh into remote site directly , you can use ssh config file to configure proxy server and port.
command_not_found_handle is even more handy
In bash4 it is possible to set up an autossh feature which is quit
handy. I'm using this for about a year now:
function command_not_found_handle() { host=$(echo $1 |sed -e 's/^.*@//g') # if hostname is found in in .ssh/config then ssh to this host if grep -q "Host $host" $HOME/.ssh/config; then ssh $* else # otherwise check for a valid hostname and try the same if found if ! getent hosts $host >/dev/null; then echo "bash: $*: command not found" else ssh $* fi fi }scripts
I have a script ~/bin/ssh_base with the following contents:
#!/bin/bash
ssh -X -C `basename $0` $*
Then I just create symlinks in ~/bin/ with the hostnames of machines to which I connect. Now all I have to do is type hostnames, and there's tab completion! I'll have to look into ssh_config more, though... I like how it simplifies connecting to a server on a non-22 port.
ssh tab...
In bash, ssh can have autocompletion too (host names from known_hosts etc.]
SSH!
Any chance to get a high res version of the poster for printing?
The site on the poster seems to be no longer around.
this is prob to the
this is prob to the biggest...
http://halbot.haluze.sk/images/2006-01/1817_ssh.jpg
found with...
http://www.tineye.com/search/8d3da6fecc2da1461ebe426434c4079cf8496b75?so...
thanks
Thanks! Unfortunately it is already gone now.
Guess I have to just look for the picture and make my own poster.
just url is slightly
just url is slightly different:
http://halbot.haluze.sk/?id=1817
SSH!
Slightly bigger:
http://codesorcery.net/wp-content/uploads/ssh.png
Shorter shortcut
Hey Mitch,
Thanks for another good tip! I came up with a slightly different solution for the same problem - to add an alias to my bashrc file:
alias server1="ssh -p 12022 mitch@example.dyndns.org"
Now I only have to type the name of the server I want to connect to...
Keep up the good work!
Nice, I like this too. Good
Nice, I like this too. Good job.