Go Back   Defender Hosting Forums > PowerVPS Virtual Private Servers > Linux VPS - HOWTOs and FAQs

Linux VPS - HOWTOs and FAQs Staff and Community HOWTOs and FAQS Covering Linux

View Poll Results: I found these instructions helpful
Yes 9 75.00%
No 1 8.33%
I don't speak linux 2 16.67%
Multiple Choice Poll. Voters: 12. You may not vote on this poll

Reply
 
Thread Tools Display Modes

  #1  
Old 03-09-2008, 04:15 AM
nick.crutchfield's Avatar
nick.crutchfield nick.crutchfield is offline
Junior Member
 
Join Date: Nov 2007
Posts: 1
nick.crutchfield is on a distinguished road
Default Securing your new VPS

Hey Everybody,

Just a friendly note from a PowerVPS tech.

Finding out your VPS has been hacked is like walking out to your car, and seeing the gaping hole where your stereo used to be. It hurts, bad.

However there are plenty of steps you can take as a VPS owner to secure your setup. Most of these are fairly basic and can halt the majority of hacking attempts.

If you need help setting up or configuring anything listed below, don't hesitate to contact support. Who knows, you could get lucky and get me for your tech!

1) Securing SSH
SSH presents a unique problem. It is necessary for system administrators to manage their servers, and because of that it raises security vulnerabilities.

For those of you who use cPanel / Plesk or Webmin-Usermin, you may not use SSH everyday, or at all. It is easy to forget about it.

1.1 don't login (or allow logins) to ssh as 'root'
The user root is way, way to powerful to be allowed direct remote access. This does not mean you need to disallow root functions over ssh. In this setup another user is first used to login to ssh, and then the sudo command is used to allow root only operations. (Don’t worry, it’s not complicated... really it’s not

First ssh in to your VPS (if you have to use root this time, so be it)
at the prompt type the command

Code:
nano -w /etc/ssh/sshd_config
this will open the Nano text editor and allow you to edit the ssh configuration

find the line

Code:
# PermitRootLogin yes
and change it to

Code:
PermitRootLogin no
hit cntrl + x to exit Nano, then hit y and then enter to save the file

Now, we need to make a user to login to SSH when root level functions need to be performed.

when you are at the command line in ssh type the following command

Code:
useradd NewUserName -g wheel
this will create a new user in the wheel group (change NewUserName to whatever you want this user to be called)

Next run

Code:
passwd NewUserName
and enter the new password for the user you just created

Please Please Please use strong passwords, they are your first line of defense against hackers. Setting your password to doggie, is about the same as locking your front door with a q-tip and some scotch tape. Google "complex passwords" for some help picking one

Now we need to edit the suddoers file. This file determines who is allowed to use the sudo command, and that is what will allow you to act like root, without actually using the root account.

Since we added the new user to the wheel group, all we need to do in here is allow the wheel group to sudo. This is already in the file so all we need to do is remove the comment in front of it. Here is how

Code:
nano -w /etc/sudoers
Find the line

HTML Code:
# Uncomment to allow people in group wheel to run all commands
# %wheel  ALL=(ALL)       ALL
and remove the # like so

Code:
# Uncomment to allow people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL
again, hit cntrl -x, then y and then enter to exit and save the file

Now, all you need to do is run the following command to restart ssh services and you done (you may get booted out of ssh after you run this command)

Code:
service sshd restart
All set, you have no disallowed the root account to login through ssh.

To login to ssh to perform root functions, use the following steps.

SSH to your server using the username and password you created above, not root.

Next type the following command

Code:
sudo su -
This will bounce you up to root for the entire time you are logged in. Alternatively you can use sudo in front of any command to run just that command as root
For ex.

Code:
sudo nano -w somefile.txt
would open somefile.txt as the root user.

1.2 Changing the SSH port

The standard port for SSH is 22, and hackers are well aware of this fact. Changing the ssh port is a great way to avoid some common brute force hacking attempts and the like.

First ssh into your VPS (using the new account and password from above and then sudoing up to root)

Edit the ssh config file

Code:
nano -w /etc/ssh/sshd_config
Now, find the line labled

Code:
# Port 22
and change it to

Code:
Port zxy
where zxy is any 4 digit number you wish, (note this number)

hit cntrl + x to exit Nano, then hit y and then enter to save the file

Now, you need to open up this new port in your VPSs firewall. If you dont know how to do this already, dont attempt it before consulting support.
Simply open a support ticket, and we will have this port opened for you in half a jif, just make sure to include the port number you have set in the ticket.

Now, restart sshd with the folowing command, and your all set. Remember to change the ssh port in whatever client ssh program you use to connect to your VPS.

Code:
service sshd restart

Last edited by nick.crutchfield; 03-09-2008 at 04:35 AM..
Reply With Quote

  #2  
Old 03-10-2008, 05:29 PM
jeremy's Avatar
jeremy jeremy is offline
Junior Member
 
Join Date: Dec 2005
Posts: 27
jeremy is on a distinguished road
Default Re: Securing your new VPS

I think powervps should automically ask new users what they would want their ssh user names and passwords to be.
Reply With Quote

  #3  
Old 03-11-2008, 06:09 AM
sdjl's Avatar
sdjl sdjl is offline
Senior Member
 
Join Date: Dec 2005
Location: London, UK.
Posts: 349
sdjl is on a distinguished road
Send a message via AIM to sdjl
Default Re: Securing your new VPS

Good tutorial.
I'd also suggest setting up SSH user identities, so that you can completely remove the use of clear text passwords. I've used this tutorial in the past: http://www.securityfocus.com/infocus/1810

David
Reply With Quote

  #4  
Old 04-09-2008, 11:57 PM
webboy's Avatar
webboy webboy is offline
Junior Member
 
Join Date: Oct 2007
Location: Nashua, NH
Posts: 3
webboy is on a distinguished road
Send a message via Yahoo to webboy
Default Re: Securing your new VPS

Smart for everyone. I may use the ssh once a month to block an IP or reset the stats. I have worked with Nick on a few issues and he is one of the good ones at Defender/PowerVPS.

I only wish PowerVPS had VPS services available in other parts of the country.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Securing an extranet ndndixie Linux VPS - Security and Tuning 1 11-30-2006 04:42 PM
A Beginner's Guide to Securing Your Server mbrando Linux VPS - Security and Tuning 4 06-26-2005 11:22 PM



All times are GMT -4. The time now is 11:51 AM.


vBulletin skin developed by: eXtremepixels
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright Defender Technologies Group, LLC 2006