On my quest of knowledge of GNU/Linux, most specifically Ubuntu Server one of the things I’m contently look at is security. I’ve known for some time that Linux is by far a more secure platform than Windows or OS X but a system is only as secure as the user using it.
What i want to cover in this post is the ability to gain entry to your server via SSH and the default root account. As i said, Linux is very secure but if you have a password such as your dogs name “Fluffy” it’s not going to be at all hard for a would be attacker to gain entry via brute force – especially if they already know the user name (root)
So what do we do. We’ll we disable root from being able to log into the server via SSH.
So let’s get started.
Login to your server (presumably you’ll be using your root account or you won’t be reading this article)
ssh -l root host.name
next, we want to edit the SSH config file so fire up nano (or vi) so we can edit the file
nano -w /etc/ssh/sshd_config
Find the following section
# PermitRootLogin yesand change it to
PermitRootLogin no
(note that we’ve removed the hash ‘#’ and also added ‘no’ at the end)
Hit Ctrl+X and save the file as you exit. So now root can’t login via SSH. Great you say but now how to I get myself in there to edit stuff? We need to add a new user who’ll have sudo privleges thats what.
So, to add a new user enter the following
useradd UserName -g wheelThis will add a new user to the wheel usergroup. Remember to change UserName for your new user name (duh)
Now set a password for the new account
passwd UserNameThis is really important. Make sure that you chose a strong password. Fluffy is not considered strong by any stretch of the imagination. Click this URL for a list of random generated strong passwords (there will never be the same password twice. Refresh it and see!)
Now we need to adjust the sudoers file so that users on the wheel account can access su features.
nano -w /etc/sudoers
Find the line
# Uncomment to allow people in group wheel to run all commands # %wheel ALL=(ALL) ALL
And uncomment the last line so it reads
# Uncomment to allow people in group wheel to run all commands %wheel ALL=(ALL) ALL
Hit Ctrl+x to exit and save the file. And then at the prompt enter
service sshd restart
If you’ve done it all correctly, the next time you try and log in as root you should receive an error message like this “Permission denied, please try again.” You should now be able to log in with your new user name and password.
So now your in, you want to preform something that requires root access all you need to do is enter
sudo su
You’ll then be asked for you password and once entered in correctly you’ll be logged in with root privileges until you end the session or type exit.
How good is that!
Have fun
This entry was posted on Friday, August 22nd, 2008 at 2:13 pm and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Title : My Boy (1)
Media: Canon EOS 350D DSLR, Adobe Lightroom, Photoshop
Description : A day out in the park with my world.
Title : Tasmania Corrective Services Badge
Media: Adobe Illustrator, Stitch
Description : Badge for the Canine Drug Detection Unit
Title : Webb Martin Consulting Website Concept 1
Media: Blog/Website, flash, css, xhtml, php
Description : Website deisgn for Webb Martin Consulting
Title : Webb Martin Website Design Concept
Media: Wordpress, CSS, xhtml, php
Description : Concept website design for Webb Martin.
Jamie Le Souef Says
If I’ve missed something here or you know of another security tip that i should look at please comment away (i do not have the nofollow tag on my comments… you so know you want to ;) )