kristau.net

Photos, Writings, Etc.

  • Home
  • Photos
  • Technology
  • Virualization
  • Linux
  • Writings
  • Travels
  • Food
  • Site News
  • Causes

Using OpenSSH for Linux administration

Posted by Kenneth Ristau on September 6, 2009
Posted in: Linux, Technology, Writings. Tagged: hints tips tricks, Linux, OpenSSH, script, ssh, technology, writings.

Here are some hints and tips for those who are new to using ssh/OpenSSH for Linux system administration. Most of these tips have come from my recent work with a large number of Linux servers hosted on a VMware ESXi 4.x server farm.

Password authentication VS ssh key authentication

  • If you are administering only a few systems on a closed network (i.e. accessible only locally or by a secure VPN connection), then password authentication is probably OK, but you should consider using ssh keys anyway.
  • If your network needs to allow ssh access directly from the Internet or you are administering a large number of systems, then you should definitely use ssh keys.
  • Here is a good HOWTO which goes over generating a few different types of ssh keys.

Ssh-agent, scripting and cron

  • ssh-agent can save you typing in the password to your ssh key every time you need it.
  • This site gives a good overview of ssh-agent and includes some code you can add to your .bash_profile script to ensure your keys get added upon login.
  • Although there are hack-ish ways to get ssh-agent and cron to work together, you are probably better off setting up special keys to use with scripts that must be called via cron. Just keep in mind that keys without passwords are a security risk.
  • If you cannot risk using keys without passwords, consider running those cron scripts locally on each system. Utilize shared file space or e-mail to collect the results.

Bash one-liners and ssh with ssh keys

  • I’ve become a fan of using bash “one-liner” scripts to keep abreast of server stats such as load averages, available patches and disk usage.
  • Keep an up-to-date list of hosts in a file called hostlist.
  • Run your one-liners while ssh-agent has your ssh keys cached.
  • Here’s a template one-liner which checks uptime on each host listed in the file hostlist:

for e in `cat hostlist`; do echo $e; ssh $e "uptime"; done

  • In the above example, you can replace uptime with just about any command which exists on the remote host.
  • You can also synchronize some of the configurations under /etc with the above by utilizing either scp or rsync instead of ssh in that one-liner.

Turn your one-liners into scripts

  • If you find yourself using the same one-liner over and over, it is time to save yourself some typing and turn it into a script.
  • I like to keep these sorts of scripts under ~/bin. I also like to add that to my $PATH and create a simlink ~/scripts.
  • Some one-liners are good candidates to be turned in to cron scripts. Just keep in mind the risks of using ssh keys without passwords, and include logic to detect conditions you want to monitor. For example, you can run /proc/loadavg through awk to isolate one of the three figures and send yourself an e-mail if that average is too high.

Posts navigation

← CIALUG August Meeting Notes
IT Applications of Sun Tzu’s Art of War: Attack by Stragagem →
  • Recent Posts

    • Spring 2023 Back Yard
    • Best of 2019
    • Best of 2018
    • Best of 2017
    • Upper Dells Boat Tour, October 2022
  • Recent Comments

    • Pam Ristau on Food Blogging is Hard (But Rewarding) Work
  • Archives

    • April 2023
    • February 2023
    • January 2023
    • September 2022
    • August 2022
    • July 2022
    • April 2022
    • October 2021
    • July 2021
    • March 2021
    • September 2019
    • May 2019
    • May 2015
    • November 2014
    • October 2014
    • August 2014
    • July 2014
    • April 2014
    • October 2013
    • May 2013
    • March 2013
    • February 2013
    • January 2013
    • September 2012
    • August 2012
    • July 2012
    • May 2012
    • April 2012
    • February 2012
    • January 2012
    • November 2011
    • October 2011
    • August 2011
    • July 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • March 2010
    • February 2010
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
  • Categories

    • Android
    • Causes
    • Food
    • Linux
    • Mac OSX
    • Making
    • Pheatured Photographer
    • Photos
    • Site News
    • Technology
    • Travels
    • Uncategorized
    • Virualization
    • Writings
Proudly powered by WordPress Theme: Parament by Automattic.