|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Sysadmin Make SSH do more
Expert use of SSH for the administrator
By: Jon Lasser
Mar. 26, 2001 12:00 AM
Because Linux is a deep operating system, we often use a miniscule portion of a tool's features. I, for one, use awk primarily to isolate columns that cut can't find, though in fact awk is a full-fledged text-processing language. There's nothing wrong with that approach -- in fact, it's unavoidable -- but it benefits us to delve more deeply into the advantages a single program can offer. Presumably you have already installed SSH and use it to securely log in to remote systems. (If you don't please read Jay Beale's article "Stupid, Stupid Protocols: Telnet, FTP, rsh/rcp/rlogin" to see why you should -- see Resources.) However, most people simply connect via SSH, enter their passwords, and type away. They don't realize that SSH has advanced key-management features that can keep you from having to retype your password; that its port-forwarding options can secure other, normally insecure, packages; and that you can employ little tricks in SSH that make your life easier. There's great confusion at present regarding SSH and the different versions of the software available. (See Resources for more information.) I recommend using the newest version of OpenSSH, 2.5.1p2. At the very least use OpenSSH 2.3.0p1, as earlier versions had security holes. Several details I discuss will not apply to older versions of OpenSSH or to other implementations of the SSH protocol. Keys to the kingdomOne major benefit of SSH, besides the obvious advantage of cryptographically secure connections, is that it allows you to log on to a server without ever having to type your password. You do have to type a password (only once -- but we'll get to that in a minute), but it doesn't have to be the password for your account on the server, and it will be the same password for every system you log in to. That is possible through the magic of authentication via cryptographic keys.Normally, when you log in to a system, you authenticate by entering your password for that system. Your password goes, as it is typed, to the remote system, which authenticates it against the That sort of authentication requires you to first generate a pair of public and private keys. The To allow authentication, you must make the public key available on the computer into which you would like to log in. For rsa1 keys, the name of the file into which you put the public key is All that is very useful, but as I promised earlier, you can set your system to only require authentication once. You can do that with the SSH authentication agent, ssh-agent. The ssh-agent syntax is rather strange: because it must set some shell variables, you must use You must execute the ssh-agent in your top-level shell for maximum usability. For a console or ssh-based session that means in your top login shell or, for X-based sessions, in your .Xclients or another startup script. In either case, you must kill the ssh agent with The ssh-agent only manages keys; you have to tell it which keys to use. To do that, you can If I plan on connecting through one server to another server, I connect via SSH to that first server with the -A option, which allows the server to pass any authentication requests it gets back to the initial client. (You can make that operation the default by setting Forwarding traffic with SSHNot only can SSH forward your authentication requests, but it can forward your X Window System traffic as well. And SSH not only forwards the traffic, but also automatically sets X's DISPLAY variable on the remote system, thus simplifying your side of things substantially. Nobody likes messing with the DISPLAY variable, Magic Cookies, or any other part of remote X configuration. SSH can handle all of those at once. You just need to connect SSH using the -X option, or setForwardX11 yes in the appropriate config files, and run your X application from the remote system's command prompt.When using X, I always make sure to turn compression on with the -C option ( Perhaps even more interesting is SSH's ability to forward arbitrary ports. Maybe you read mail on a server that you can also SSH into, and POP3 mail is running but secure POP3 is not. You therefore wish to forward a port on your workstation to the POP3 port on the server. Let's pick an arbitrary port, such as 2048. Configure your mail client (such as Netscape) to connect POP3 to port 2048 on localhost (that is, your workstation). Then you can run the following command: What's happening here? -N tells SSH that you're not interested in running a command on the remote system, only in forwarding the connection, and -f tells SSH to go into the background once you've authenticated your connection. That way, after you've entered your passphrase (or once ssh-agent has authenticated you), you won't need to type more. The magic part is That method works very nicely for most protocols, including POP3, HTTP, and IMAP, just so long as you're able to tell the client server to use the local system and the appropriate port on your local system. For FTP, be sure to use passive FTP, because active FTP opens a second connection that will not be forwarded via the SSH port forwarding. Recent versions of OpenSSH, and Commercial SSH version 2 support SFTP, which works like FTP and uses SSH without the difficulty of port forwarding and passive mode. Tricks and trapsBecause SSH command syntax descends from the outdated and dangerous rsh syntax, several neat tricks are possible. My favorite is piping data through SSH to a program on the remote side. For example, I haven't configured printing on my laptop, as I can't be sure what device I'll want to print to. Instead, I can runcat /my/file/to/print.txt | ssh jon@my.remote.printhost lpr -Pwhich_printer, which pipes the file to the program lpr on the remote side of things. Essentially, anything after the destination host on the SSH command is passed as a command to the remote server. If disk space is tight, you can also use that trick to tar files to a storage place on a different system: tar cvf - source_directory | ssh user@remote_host 'cat > my-tar-file.tar'. The quotes are necessary to ensure that the remote system, and not the local system, redirects output.One trap associated with executing commands via SSH is that interactive programs tend to die unhappily. That is generally because they expect a terminal to be available, and SSH does not allocate a terminal for commands that it does not believe to be interactive. For example, I keep nethack on one system and I execute it via a script that calls Another trap is that dangerous configurations of the SSH client drop back to the notoriously insecure rsh program if the remote system does not have SSH installed. Your SSH client should print out an error message under those circumstances, and you would be ill advised to ignore it. You can disable that behavior with a line reading Although this article hardly covers every facet of SSH, hopefully you have learned a few new ways to use it. I've recently freed myself from the annoyance of typing passwords frequently. As a system administrator, I find that using SSH to run commands on remote systems helps me manage them efficiently, both by executing the same command on multiple systems (such as package upgrades) and for remote data collection (such as running uptime and sending the output to a file). As a user, I find that, once ssh-agent is configured properly, my work day proceeds more smoothly. Reader Feedback: Page 1 of 1
Your Feedback
SOA World Latest Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||