Home > Articles > Security > Software Security

📄 Contents

  1. Why Not RSH?
  2. SSH: The "Ssafer" Alternative
  3. Conclusion
  4. Resources
  • Print
  • + Share This
Like this article? We recommend

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.

Security Levels



Minimal Security

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.

Better Security

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.

Best Security

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:

AuthorizedKeysFile /LocalFS/%u/.ssh

Be sure that permissions are set correctly on these items:

  • Directory: 700

  • 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!

  • + Share This
  • 🔖 Save To Your Account