Skip to main content

How to Block Root Password-Guessing Attacks on a Linux Server


How to Block Root Password-Guessing Attacks on a Linux Server


The benefit of performing the preceding steps is that it is nearly impossible for an attacker to log on to your server as root by guessing the password.  In order for the attacker to masquerade as root, she or he would have to have your private key and know the pass phrase associated with it.


Using Cryptographic Keys for SSH Root Login

Take one look at /var/log/secure on an Internet-connected server and you'll immediately understand the need for securing your root account.  The bad guys are constantly attempting root and other usernames to attempt to login to your server using SSH or some other protocol.  If you use a simple password, it's only a matter of time before your server is compromised by a password-guessing attack.
Best practice is to disallow SSH logins by root, thus eliminating a big part of the risk.  The problem is that doing so also eliminates a lot of convenience for sys admins and complicates the use of tools such as Filezilla or WinSCP for file copy from your Windows desktop or laptop to your Linux or UNIX server.
A fairly simple solution is to use public/private keypairs for authentication.  The public key is stored on the Linux/UNIX server and the private key is stored on your local Windows computer.  When you attempt to connect to the Linux/UNIX server from your Windows computer, authentication is done with the keypair instead of a password.  Password authentication is actually disabled for root, so no amount of password guessing will work for authentication.
Here's how to do it:

Requirements:
•             PuTTY
•             PuTTYGen (Just download the PuTTY Windows installer.  It includes everything you need.)
•             Local computer running Windows
•             Remote computer running Linux or UNIX

Remote Files:

•             /etc/ssh/sshd_config
•             /root/.ssh/authorized_keys

1.            Start by downloading the PuTTY Windows installer.  Run the installer on your local Windows computer.
2.            Now, you must generate the keypair.  The PuTTY Windows installer you just ran installs an application called PuTTYgen that you can use to generate the keypair.  The installer probably placed PuTTYgen (and the other PuTTY applications) in Start>>All Programs>>PuTTY.
3.            When you run PuTTYgen for the first time, you must generate a new keypair.  At the bottom of the PuTTYgen window are three parameters choices including SSH-1 (RSA), SSH-2 RSA, and SSH-2 DSA.  SSH-2 RSA is the default choice with a default key length of 1024 bits.  Longer key lengths are more secure, but require more processing power.  1024 bits is an acceptable compromise at this time (late 2010), but may not be acceptable in the future as computer processing power continues to increase.

4.            Click the button labeled Generate to produce your public and private(You must move your mouse pointer over the blank area at the top of the screen to generate some randomness for use in producing the keypair.  Just move your mouse pointer in a cirular motion over the blank area until the progress bar reaches the far right side PuTTYgen generates the keys).


5.            You can now save the private key on your local laptop or desktop computer and copy the public key to the remote Linux/UNIX server.
6.            Enter and confirm a passphrase to protect the private key in the two fields in PuTTYgen.
7.            Click the button labeled Save private key and select a location on your local hard drive to save the private(Remember to protect your private key by storing it securely!)  I also like to save my public key as a text file to simplify using it in the future.
8.            Copy the jibberish text that is the public key (at the top of the PuTTYgen window) and paste it into /root/.ssh/authorized_keys on your server (You might have to create the .ssh directory and you'll probably have to create the authorized_keysNote also that the .ssh directory is a hidden directory whose name starts with a period.).  If you saved your public key as a text file in the previous step, you can simply copy the contents of that file to /root/.ssh/authorized_keys.
9.            On your Linux/UNIX server, inspect /etc/ssh/sshd_config to ensure that RSA authentication and public key authentication are both allowed by modifying three lines in the sshd_config.  Depending on your system, you will have to change "no" to "yes" or uncomment the lines to allow the authentication.  Also, ensure that the path to the authorized_keys file is set to "%h/.ssh/authorized_keys" and uncomment the line.  (I found the three lines at approximately line 43 on a RedHat system and approximately line 29 on a Debian system.)  When you're done, the lines should look like this:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
10.          In order for the changes to be read into RAM, you must restart SSHD:


11.          If you attempt to log on now with the username root and the root password, the logon attempt will be denied:

12.          You must now configure PuTTY to use the public/private key pair for Open PuTTY, in the left-hand menu area expand SSH and select Auth.  On the right-hand side of the window, browse to the location where you stored your private key or simply enter it in the field below “Private key file for authentication:



13.          Again, in the left-hand menu, select Session (at the top of the list).  On the right-hand side of the screen, enter the IP address or hostname of your Linux server and click the button labeled “Open”.
14.          When PuTTY connects to the server, enter “root” for the You will be prompted for the passphrase you configured for your private key.  Enter the correct passphrase and you should be logged on to your server as root.


END























Comments

Popular posts from this blog

Links to various tools, calculators, config template etc.

Below are the links to various tools, calculators, config template etc. I hope you guys will find it helpful – APC Datacenter Tools ACL Wildcard Mask Calculator Aircrack-ng APC Product Selectors BackTrack Linux – Penetration Testing Bandwidth Calculator Bandwidth Speed Test Tool Bandwidth VoIP Availability Check Bandwidth VoIP Test Belkin Wizards Black Box Custom Cable and Adapter Wizards Boson Free Utilities, Cisco Config Register Calculator Brad Reese music work ambience Broadband Tools Cain – Windows Based Hacking Tool CertSearch Tool – rates Cisco practice test providers CIDR Report CIDR / VLSM Supernet Calculator Cisco 827/827H/SOHO97/837 ADSL Firewall IPSec Config Cisco 827/827H/SOHO97/837 ADSL IPSec Config Cisco 827/827H/SOHO97/837 Basic Config Cisco 827/827H/837 Business Config Cisco 827, 827H, 837, SOHO97 Config Wizard Cisco 851/851W/857/857W/871/871W/877/877W Wizard

Smoothwall Express 3.0 with Multiple NAT

This is a must have for any Smoothwall Express Setup. This mod gives you full control of your interfaces including multiple IP addresses, ports and mac control: The mod gives ultimate control with the following: 1.    Specify origin source IP/Network 2.    Specify the origin/destination ports to be open for your specific IP/Network e.g. Open access for the IP 222.111.55.333 on port 57 to your IP xxx.xxx.xxx.xxx on port 22 To install the mod simply run the following from command line: 1.   wget http://stans-smoothwall3mods.googlecode.com/files/fullfirewall-3.3.3.1-Express-3.0-i386.run 2.   sh ./fullfirewall-3.3.3.1-Express-3.0-i386.run **NOTE: Smoothwall Express 3.0 should be up to and including update 9 – Maintenance > Updates. Log back into the Smoothwall GUI and you will now see the Full Firewall Control interface. control ,  full firewall ,  mod ,  port forwarding ,  smoothwall For further reading take a look at below link:  https://www.linuxtutoria

Useful site for system & network admin

https://wintelguy.com/ Site Contents: MAC / WWN Lookup RAID Calculators DWPD, TBW, GB/day Calc. TB / TiB / GB / GiB Converter Backup Calculator Virtualization Calculators IP Subnet Calculator Network Throughput File Transfer Time Calculator WAN Latency DNS Lookup IP Locator eMail Tracer WHOIS Port Database Search Password Generator Power Unit Conversion Text Tools Cost Calculators