| Private Hosting Questions about VPS, dedicated servers and colocation. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
|
|
#1 (permalink) |
|
Just Some Guy..
Comfy Contributor
Joined in Oct 2003
127 posts
Gave thanks: 0
Thanked 5 times
|
Several customers have asked about how to keep your server's secure, particularly access via SSH. This post will try to explain how best to do that.
First off, let me say, no matter what you do, keeping your root password complex and constantly changing is extremely important. After this if I see ANY of you with the default root password we set on your server, I will drive/fly to where you live and slap you silly, understand? SAY NO TO DEFAULT ROOT PASSWORDS. ![]() There are two ways to change your password:
OK, so now you have a nice, long, alphanumeric password that also contains special characters (-,!,#, etc.) and some random upper- and lower-case characters and isn't based on ANY words found in a dictionary. Don't forget to change your root pass regularly! (Once a month is probably good, or more often if you think you need to do so.) If any of you have done some research on the subject of Linux security, you're probably aware that "experts" reccomend that when it comes to SSH security you:
This will certainly make your server safer. However, there are a few drawbacks to all that, which I'll get into later, as well as another method of securing SSH access that is less problematic and even safer than SU to root. Most of the changes listed above can be accomplished just by editing a single file. To start, just log into your server via SSH as root and type the following: Code:
pico -w /etc/ssh/sshd_config In case you don't know this, any line that begins with a "#" is COMMENTED (which means it is ignored, it's typically used for comments, hense the name). You should see a block that looks something like this near the top of the filw Code:
#Port 22 #Protocol 2,1 #ListenAddress 0.0.0.0 Uncomment the first line #Port 22 (remove the #). Now change this to any unused port, try to stay away from obvious choices like 222, 2222, 1234, etc. Also, if you are running APF (and you SHOULD BE), you will also need to edit the conf.apf file later to add whatever port you just chose to the ALLOWED ports (ingress/egress) and restart APF later. Don't forget or you will lock yourself out of SSH! Now uncomment the second line. All you need to do here is remove the ",1" at the end of the line, so it looks like: Code:
Protocol 2 Scroll down until you see the following lines: Code:
#LoginGraceTime 120 #PermitRootLogin yes #StrictModes yes Also uncomment the next line (StrictModes). Scroll down a little further for one last change: Code:
# To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no Now save the file. To do that, press CTRL-X, Y, ENTER. Before we restart anything, we need to add a user to be in the wheel group (this will be the account that can SU to root later). Type: Code:
useradd -g wheel -s /bin/bash -p passwordhere newusername Don't forget this password and make it a SECURE one! If all has gone well, you can now restart SSH and test it out. PLEASE MAKE DOUBLY SURE YOU DIDN'T MAKE ANY MISTAKES BEFORE RESTARTING SSHD Also, make sure to edit conf.apf if you have APF installed to add the new SSH port. To restart it type: Code:
service sshd restart Once in, you now have to SU to root, type: Code:
su You will now have most of the powers that the root user has (with a few exceptions). When you want to log out, type "exit" 2x. Congratulations, your server is much safer now. However, there are a few things to consider:
There is another way to access root directly WITHOUT permitting someone to log in via the root password. The secret is using public/private keys. You will create a public/private key pair, upload the public key to your server, and keep the private key on your personal computer (don't put your private key on any computer that you share with anyone else, for safety). If you don't understand what a public/private key is and how such encryption works, visit pgp.com to learn more about it. How do we do this SSH key thing? Let's back up to the point where we were first editing the sshd_config file earlier. Code:
pico -w /etc/ssh/sshd_config Scroll down until you see the following lines: Code:
#LoginGraceTime 120 #PermitRootLogin yes #StrictModes yes Code:
PermitRootLogin without-password Save the changes. DO NOT RESTART SSHD, we still have work to do. If you are running Windows, you probably use Putty to access SSH on your server. As it happens, Putty comes with a key generator you can use. If you don't use Putty and your SSH client can't create keys, then you can use PGP (free or paid version) to create a key pair, but you will have to edit it so it is a single line (rather than block) and contains the appropriate header info. If you use a Mac with Mac OS X, you've already got a key generator installed on your computer. Note: For security I recommend that if you already use keys for other purposes (sending/receiving mail, etc.) that you still create a NEW key pair just for SSH with a completely different password. Generating a Key Pair Under WINDOWS Using Putty:
CONTINUED, NEXT POST |
|
|
|
| This user thanks Aric for this great post! | shakh (November 26th, 2007) |
|
|
#2 (permalink) |
|
Just Some Guy..
Comfy Contributor
Joined in Oct 2003
127 posts
Gave thanks: 0
Thanked 5 times
|
SSH and Security, Part 2
Generating a Key Pair Under MacOS X/Linux Using the Command Line/Shell:
Installing the Public Key on Your Server:
Testing Your New SSH Key and Finishing Up:
Benefits to using SSH keys:
If you haven't already installed APF/AD/BFD on your server, or rootkithunter, or updated logwatch, you should do so now. Also, don't give SSH to ANYONE unless you absolutely HAVE to, and if you MUST do so, make sure it is a jailshell. [EDIT:] I knew I forgot something else I wanted to add... A discussion of how you can be notified via e-mail whenever someone successfully logs into your server as root. This can be handy since most of you probably only have yourselves or perhaps 1-2 others typically logging into your server(s). This can give you a heads-up if you see a root login you don't expect to check your server. To do that, log in as root to your server using your new SSH key and then do the following from the /root directory (which should be where you start): Code:
pico -w .bashrc Code:
echo 'ALERT - Root Shell Access (YourserverName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" you[at]yourdomain.com
Replace you[at]yourdomain.com with your actual email address Press CTRL-X, Y, ENTER/RETURN to save the changes. Now go ahead and log out and back in. Shortly thereafter you should get a mail with the hostname, date, time and who it was that tried to log in (typically this will be the reverse DNS record of an IP address or the IP address itself). This isn't meant to be a complete list of every security precaution you could/should take, but it is an important first step. Regards, Aric |
|
|
|
|
|
#3 (permalink) |
|
Forum Moderator
Super #1
Joined in Aug 2003
Lives in Norway
Hosted on Minerva
1,215 posts
Gave thanks: 0
Thanked 0 times
|
Thank you Aric! Will get use for this guide as i get my first surpass dedicated setup. (Ordering today.)
__________________
Owner of Minerva and Server :: Beatiful P4's @ Surpass http://www.case-spider.com Winner of the Surpassies 2004 - Most Spirit. :bravo: Google = Friend! |
|
|
|
|
|
#4 (permalink) |
|
Registered User
Fresh Surpasser
Joined in May 2004
15 posts
Gave thanks: 0
Thanked 0 times
|
I would reccommend all users to read the following post as well :
http://www.webhostingtalk.com/showth...l&pagenumber=1 Gives a really basic intro to cPanel/WHM security that SHOULD be in place on all dedicated servers.
__________________
Server : Dedicated :surpass: |
|
|
|
|
|
#6 (permalink) |
|
Forum Moderator
Super #1
Joined in Aug 2003
Lives in Norway
Hosted on Minerva
1,215 posts
Gave thanks: 0
Thanked 0 times
|
Thanks. And yes, read the one matsbs gave you too. Good tips there.
__________________
Owner of Minerva and Server :: Beatiful P4's @ Surpass http://www.case-spider.com Winner of the Surpassies 2004 - Most Spirit. :bravo: Google = Friend! |
|
|
|
|
|
#7 (permalink) | |
|
Just Some Guy..
Comfy Contributor
Joined in Oct 2003
127 posts
Gave thanks: 0
Thanked 5 times
|
Quote:
The kernel's we install are more secure than your run-of-the-mill kernel (which that post would have you install). Plus the directions for APF, etc. are out of date. |
|
|
|
|
|
|
#8 (permalink) |
|
Forum Moderator
Super #1
Joined in Aug 2003
Lives in Norway
Hosted on Minerva
1,215 posts
Gave thanks: 0
Thanked 0 times
|
Hmm. Planning a guide on APF and BFD for your servers then Aric?
![]() Will give you a beer next time i meet you then.¨ Edit: Just noticed your already created guide on that. Owe you a beer now. ![]()
__________________
Owner of Minerva and Server :: Beatiful P4's @ Surpass http://www.case-spider.com Winner of the Surpassies 2004 - Most Spirit. :bravo: Google = Friend! |
|
|
|
|
|
#9 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Sep 2004
17 posts
Gave thanks: 0
Thanked 0 times
|
I did what you said, up to the part with logging in with the new IP and port, when i try using the new user name, my ssh just closes... now i cant get in, i double checked before i restarted, it doesnt say an error, it just closes!!! i over looked the add -withoutpassword part !! oh crap...
__________________
Negative-Shock.net Last edited by andy - ns; December 17th, 2004 at 8:36 PM. |
|
|
|