Securing OpenSSH

A tutorial on the holistic approach to securing OpenSSH.
OpenSSH Options

OpenSSH has a number of configuration options that can be employed to reduce risk. Most Linux distributions come with good middle-of-the-road settings. In some cases, these can be adjusted for better security. These include:

  • Logging: turn up the logging level to INFO or DEBUG. Examine your logs on a regular basis, or better yet, implement one of the many available log analysis tools to notify you of anomalies:

    LogLevel INFO

  • Privilege separation: make sure the UsePrivilegeSeparation option is enabled:

    UsePrivilegeSeparation yes

  • Protocol: limit OpenSSH to accept only protocol version 2:

    Protocol 2

  • Root logins: prevent root logins using passwords. This limits root access only to nonpassword methods like public key authentication. If you never directly log in as root, set this to no. You always can log in as a regular user and su to root or use sudo. Setting this to without-password allows only nonpassword methods, such as public key authentication:

    PermitRootLogin without-password

  • File permissions: make sure StrictModes is enabled to prevent the use of insecure home directory and key file permissions:

    StrictModes yes

  • Reverse name checking: require OpenSSH to check proper reverse hostname lookups. Note that you must have proper name lookups working (that is, DNS or /etc/hosts):

    VerifyReverseMapping yes

  • Prevent port forwarding: these two options prevent OpenSSH from setting up TCP port and X11 forwarding; if you do not need these features, disable them:

    AllowTcpForwarding no
    X11Forwarding no

  • Disable all host-based authentication: always make sure these are disabled. These methods assume that the network can be trusted and allow .rhosts-style authentication based on hostname or IP. Never use these methods as primary authentication:

    IgnoreRhosts yes
    HostbasedAuthentication no
    RhostsAuthentication no
    RhostsRSAAuthentication no


Using the above suggestions, you will be able to tighten access controls and eliminate sloppy trust relationships. As I mentioned earlier, staying current with updates or patches is critical to system security. In order to stay current, you need to be informed of when updates are released, so I suggest a multipronged approach. First, automate apt, yum or up2date to check nightly and report on missing updates. Second, subscribe to your Linux distribution's security mailing lists. Third, subscribe to one of the many security discussion groups, such as SecurityFocus. If you build OpenSSH from sources, join the OpenSSH mailing list to watch for updates.

System security requires a holistic approach. The methodologies provided in this article form the basis for securing OpenSSH, one small component of a modern complex Linux system.

After you believe you have secured your system, use scanning tools like the free Nessus Vulnerability Scanner (see Resources) and peer review from colleagues to check your work.

Resources for this article: /article/9023.

Matthew E. Hoskins is a Senior UNIX System Administrator for The New Jersey Institute of Technology where he maintains many of the corporate administrative systems. He enjoys trying to get wildly different systems and software working together, usually with a thin layer of Perl (locally known as “MattGlue”). When not hacking systems, he often can be found hacking in the kitchen. Matt is a member of the Society of Professional Journalists and can be reached at


White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState