Demons Seeking Dæmons—A Practical Approach to Hardening Your OpenSSH Configuration
Chances are, if you are the owner or administrator of a Linux machine, you access it remotely from time to time, if not constantly. Be it a workstation at home, a co-located server or a hobby machine, if you are accessing Linux remotely, there is a good chance that you are using the OpenSSH server on the remote machine with some type of SSH client locally. (If you are not, you probably should be.) Although it is true that the OpenSSH server and clients do a tremendous job at encrypting the traffic that passes between systems, it also is true that any dæmon listening for connections is a door handle waiting to be turned by the black hats, the evildoers or the crackers. The less-desirable folks in these situations are, as the title states, demons seeking dæmons, a person or group of people that usually are up to no good seeking listening dæmons that, depending on the configuration of the machine, may or may not be secure. Hackers can be defined as people who have relatively benign motives for breaking into a system. Crackers often are thought of as hackers with malicious intent. Neither the former nor latter is welcome on my machines. In this article, I expand on the basic OpenSSH configuration and cover ways to improve the security of the SSH dæmon to offer more protection to your machines. If you have a machine that suffers a compromise, your machine may be helping to spread your unpleasantness to others as well. The Internet is one of the largest insecure data routes on the face of our planet.
OpenSSH provides the means for secure communication over insecure channels. The file sshd_config is the ruling party in the game of secure shell configuration. The sshd_config file consists of multiple options that can be changed to help improve the security of the listening dæmon. Although it may seem that because it is a remote access tool it should be secure right out of the box, this is hardly the case. For the most part, a default installation of the OpenSSH server will provide you with a relatively secure default configuration but one that can be improved substantially by the machine's administrator.
When planning for remote access initially, it is suggested that you consider three major things for the access of your machines:
Who will be allowed access to the machines?
How will this access be provided?
From where will this access be allowed?
We are going to assume that we will be using the OpenSSH server to provide remote access. This leaves us with the questions of who will be allowed remote access and from where they will be allowed. For some, this may be simple; perhaps the machine supports only a single user and remote access is carried out from a single domain. For others, this can be quite a challenge when multiple users that travel frequently are the machine's users.
The first and foremost person on a Linux machine is the root user. This is universally known, and it also should be universally known that if you need to have remote root access to a machine, there are many better ways to access as root than simply using SSH and logging in as root. If you think about the fundamentals of a brute-force attack attempt, it is obvious that the most relevant account that will be attacked is the root account. One need not guess whether the account is present; it is there. The sshd_config file lets us specify that root is not allowed to log in remotely at all through the PermitRootLogin directive.
I fully believe that the saying “an ounce of prevention equals a pound of cure” is highly accurate when dealing with remote-use accounts. Two options allowed in the sshd_config file, UsersAllow and UsersDeny, are more than an ounce of prevention, and although it may be one extra step when adding an account, modifying the UsersAllow for each account added provides that pound of cure that you may (thankfully) never need to seek. To expand on the UsersAllow directive, you cannot specify only particular users, but you also can specify particular users at specific hosts. So, if in advance you know exactly who will need to log in and from where, the minimal time overhead associated with adding these directives to the sshd_config file provides the peace of mind for you to know you are allowing remote access for only specific accounts from specific machines. Valid users can be retrieved from the /etc/passwd file in standalone machines or from the corresponding files in NIS or LDAP environments. Listing 1 is an example of parsing the previous month's security files to verify which accounts have logged in successfully using SSH.
Webinar: 8 Signs You’re Beyond Cron
On Demand NOW
Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.View Now!
|Dr Hjkl on the Command Line||May 21, 2015|
|Initializing and Managing Services in Linux: Past, Present and Future||May 20, 2015|
|Goodbye, Pi. Hello, C.H.I.P.||May 18, 2015|
|Using Hiera with Puppet||May 14, 2015|
|Urgent Kernel Patch for Ubuntu||May 12, 2015|
|Gartner Dubs DivvyCloud Cool Cloud Management Vendor||May 12, 2015|
- Initializing and Managing Services in Linux: Past, Present and Future
- Dr Hjkl on the Command Line
- Goodbye, Pi. Hello, C.H.I.P.
- Using Hiera with Puppet
- Mumblehard--Let's End Its Five-Year Reign
- Gartner Dubs DivvyCloud Cool Cloud Management Vendor
- Infinite BusyBox with systemd
- Urgent Kernel Patch for Ubuntu
- It's Easier to Ask Forgiveness...
- A More Stable Future for Ubuntu