13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 6 ■ SECURING YOUR SYSTEMS6-2. Managing Keys with KeychainAs discussed in the previous recipe, using SSH keys has many advantages, but one of the major onesshows up only if you use keychain to manage your keys. keychain is a small script that improves on sshagent.ssh-agent will cache your keys for you (so that you need to enter your passphrase only once perterminal session for each key), but by default, it won’t run across shell sessions. So, if you set it to start inyour ~/.bash_profile, you’ll still have to type your passphrase once per new terminal session.■ Note If you use GDM, ssh-agent will start by default on login. Otherwise, add this line to your ~/.xsessionfile:ssh-agent gnome-sessionsubstituting in whatever window manager you use for gnome-session. Now, to add a key, type ssh-add~/.ssh/key_name.keychain improves on ssh-agent by checking for a running ssh-agent process when you log in andeither hooking into one if it exists or starting a new one up if necessary. (Some X GUI environments alsohave something similar available.) To set up keychain, first install the keychain and ssh-askpasspackages for your system. For Debian/Ubuntu, use this:sudo apt-get install keychain ssh-askpassNow edit your ~/.bash_profile file to include these lines:01 #!/bin/bash02 /usr/bin/keychain ~/.ssh/id_rsa ~/.ssh/id_dsa > /dev/null03 source ~/.keychain/hostname-shIn line 02, you should include the paths to any keys that you want keychain to manage; check your~/.ssh directory. For example, if you’ve used recipe 6-1, you’ll have a ~/.ssh/root_key key, and line 02will read as follows:02 /usr/bin/keychain ~/.ssh/id_rsa ~/.ssh/id_dsa ~/.ssh/root_key > /dev/nullRoute the output to /dev/null to avoid getting the agent information output to the screen everytime you start a new terminal. Line 03 sources ~/.keyring/hostname-sh (which is created when keychainfirst runs to store ssh-agent information) to access SSH_AUTH_SOCK, which records the Unix socket thatwill be used to talk to ssh-agent. Obviously, you should replace hostname with the name of the hostyou’re using.The first time the keychain process is started up (so, the first time you log in after setting this up),you’ll be asked to enter the passphrases for any keys that you’ve listed on line 02. These will then bepassed into ssh-agent. Once you have a bash prompt, try logging into a suitable machine (that is, one137Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!