By Russ Hunter
Date: Jan 30, 2004
Running RSH is like leaving your house keys under the welcome mat. SSH offers the same convenience and functionality with far greater security, so why haven't you switched?
Why Not RSH?
RSH (including rcp and rlogin) has been around for a long time. When RSH first came onto the scene, it was an essential tool for UNIX users. By logging into just one system, a user could run commands on any server where he or she had an account and an .rhosts file. Files could be copied from server to server as easily as from directory to directory. With a well-configured RSH environment, a user could type his password first thing in the morning and never have to type it again as he used rlogin to jump from system to system.
"Tell us more, Grandpa!"
"Well, we had to walk six miles in the freezing rain just to get to a green screen terminal with Internet access. But we only typed our password once! It was a golden age, kids!"
So what went wrong? Well, in those days security wasn't a big issue. RSH is convenient, but it has some serious security shortcomings. Like Telnet and FTP, RSH traffic is passed as clear text. If you connect to a server via rlogin and su to the root account, you're sharing that root password with anyone who happens to be listening in on your traffic.
"But our network is strictly switched, and security is good. No one can penetrate our perimeter!"
That may be good enough to keep out the casual hacker, but what if someone discovers a new router exploit and gains access before a patch is released? If you're not practicing defense in depth, the best you can hope for is a red flag on your company's next security audit. The worst-case scenario is an intruder with a free pass to every UNIX server on your network. If this happened, would you want to tell your CIO that the breach could have been prevented?
Reasons Not To Change
Inertia is a powerful force in the IT realm. "If it ain't broke, don't fix it" is an all-too-common refrain when discussing production systems. Many organizations have been using RSH for years, and aren't comfortable with change. In addition to user complaints that ensue if rsh is taken away, automated processes may rely on rsh. If these processes are poorly documented (and at least some of them usually are), disabling RSH is sure to break production. This is a valid concern, but it shouldn't be an excuse to disregard the risks inherent in rsh. We'll deal with those production issues later on.
SSH: The "Ssafer" Alternative
SSH provides all the functionality of rsh, rcp, and rlogin, and does so in a much safer manner. There are two versions of the SSH protocol, appropriately called SSH1 and SSH2. SSH1 has some inherent security issues of its own, so SSH2 is the version to consider. For this discussion, we'll use the terms SSH and SSH2 interchangeably.
SSH provides a secure environment by encrypting network traffic between hosts. To do this, SSH relies on the principle of public key cryptography.
In public key cryptography, a pair of encryption keys is used to encrypt and decrypt messages. One key is public, and the other private. A host's public key can be used to encrypt messages to that host. Only the matching private key can be used to decrypt those messages. So long as the private key is not compromised, messages encrypted with the public key can only be decrypted by the intended recipient.
By encrypting traffic, SSH helps to prevent man-in-the-middle attacks, and makes it far more difficult for hackers to "listen in" on your session. Pretend for a moment that someone has gained root access to one of the hosts on your network. You log into that server, and from there log into a remote server and su to root. If you're using RSH, the bad guy can easily sniff clear-text traffic and get the root password for that remote server. But if you're using SSH, that password you just sent is encrypted before it reaches the intruder's prying eyes, and can only be decrypted by someone with access to the private key stored on the remote server. Although SSH won't prevent every security breach, it can certainly minimize the damage when a breach occurs.
Migrating Users from RSH to SSH
From the user's perspective, switching from RSH to SSH can be as easy as using s instead of r when running commands. The commands ssh, scp, and slogin can easily double for rsh, rcp, and rlogin after the environment has been set up.
If users are exceptionally resistant to change, just symlink the r* commands to their s* equivalents when you're ready to migrate everything.
To migrate users from RSH to SSH, a bit of preparation is needed. The first step is to set up the SSH daemon on every host. Your operating system vendor likely provides an SSH server daemon suitable for use on your systems; if not, OpenSSH offers versions of SSH for pretty much every *nix system out there. (They also offer an SSH FAQ and man pages for all the SSH commands.) The installation of sshd is pretty straightforward; you'll probably spend the most time on the configuration file. Have a look at the sshd_config man page before you begin, and chart out the options you want to use.
As part of the sshd installation process, you'll be generating a public/private key pair for the host. After you have sshd up and running on all your hosts, gather all the public host keys into a single file and load it on each host. This file is saved as /etc/ssh/ssh_known_hosts. Each time a user connects to another host, SSH checks this file for that host's public key, and the connection request sent is encrypted using this key. The public key for the user is then passed to the remote host. All traffic sent back from the remote host is encrypted with the user's public key.
Public keys for hosts can also be stored in ~/.ssh/known_hosts. When a user connects to another system via SSH, if that host's public key is not found on the client system the user will be warned that the remote host's identity has not been verified. The user then has the option of adding the host to the known_hosts file, or canceling the connection.
SSH's private key encryption protects users against DNS hijacking attacks. Even if an attacker can hijack a server's traffic (and even return the appropriate public key when users try to log in), he won't be able to decrypt the SSH traffic sent from the client because he doesn't have the appropriate private host key. By maintaining an up-to-date version of the /etc/ssh/ssh_known_hosts file on all hosts, and educating your users about host-key warnings, you can verify the identity of any host on your network each time you connect.
The next step is to set up keys for all users to mimic rsh functionality. There are also some choices to be made regarding the level of security required for your environment. Although I hope you'll choose to go with the most secure configuration available, any of the SSH options are more secure than plain RSH.
Host-based authentication via /etc/ssh_host_rsa_key file. The only real advantage this security level offers over rsh is the encryption of all traffic between hosts.
One key pair generated for each user and distributed to all hosts. If you choose this route, keep in mind that if an account is compromised on one host, it will been compromised on every host.
Key pair generated for every user on every host. Creating a different key for each host requires the most work, but it offers the greatest security.
For added security, you can require each user to enter a passphrase before his or her private key can be accessed. If you choose this method, you must add ssh-agent to the appropriate profile files for your shells (such as /etc/profile or ~/.profile for Bourne, or /etc/bashrc or ~/.bashrc for Bash). ssh-agent runs when a user logs in, and manages the user's access to his or her private keys.
If you serve up home directories via NFS, there are some additional considerations. If the private key is stored in an NFS home directory, the contents of each user's private key file will be transmitted in the clear every time he or she logs in. One solution that protects against this possibility is to set up a directory just for SSH keys under a local filesystem on each host, and link the ~/.ssh NFS directory to a corresponding local user directory:
[/NFS/home/rhunter] $ ls l .ssh lrwxr-xr-x 1 rhunter rhunter 25 8 Dec 03:05 .ssh -> /LocalFS/rhunter/.ssh/ [/NFS/home/rhunter] $ ls ld /LocalFS/rhunter/.ssh drwx------ 5 rhunter rhunter 170 4 Dec 04:35 /LocalFS/rhunter/.ssh/
You'll also want to modify the AuthorizedKeysFile directive in your sshd_config file:
Be sure that permissions are set correctly on these items:
Private key: 600
Public key: 644
As for generating the user keys themselves, the best solution probably depends on your environment and user level. You can inform users of the change to SSH, and give them a script to run that calls ssh-keygen with the appropriate switches. The script can then use an automated process to move the keys out to other hosts, or notify you that the keys are ready to be moved. If users require a greater level of hand-holding, you could script a process that will su to each user account, generate key pairs for that user, copy the public keys to a central repository, and distribute the public keys to all hosts. Either way, once the keys are in place, users will be able to ssh with little or no greater effort than rsh requires today.
After users have been migrated from RSH to SSH, the last big hurdle is dealing with automated processes that might use RSH. Migrating these processes to SSH isn't hard once you identify them, but making sure that you've caught all of them before you disable RSH is critical. After you've dealt with the known processes, the safest approach is to sniff for RSH traffic on your network for a week or so. Ideally, you won't see any RSH connections at this point. But if you do, it should be fairly easy to look at the traffic and identify the owner, source, destination, and purpose. Work with the owner of the process to migrate to SSH. Once you're confident that you've dealt with all your rsh traffic, disable rshd on all hosts. For added protection, you can block traffic to port 514 on your firewalls and routers.
Congratulations! You're now RSH-free!
Switching from RSH to SSH isn't a blanket defense against hacking, but it is one of the more significant steps you can take to protect your servers. No organization that's serious about security should be running RSH. Migrating from RSH to SSH requires some planning and effort for any organization, but the dangers of an unencrypted protocol that doesn't require passwords make it imperative that all organizations do their part to stamp out this insecure legacy of the "good old days."
OpenSSH portable source for all operating systems
OpenSSH binaries for Solaris
OpenSSH binaries for HP-UX
OpenSSH binaries for AIX