Chat with us, powered by LiveChat
Securing Your Server with SSH access

Securing Your Server with SSH access

Following measures that can be taken to secure your server, with SSH access.

Update OS, Apache and CPanel to the latest stable versions which can be done from WHM/CPanel.

# Restrict SSH Access

To restrict and secure SSH access, bind sshd to a single IP that is different than the main IP to the server, and on a different port than port 22.

SSH into server as root.

# vi /etc/ssh/sshd_config

Go to the following section:

#Port 22
#Protocol 2, 1
#ListenAddress 0.0.0.0
#ListenAddress ::

Uncomment and change

#Port 22

to look like

Port 3999 (choose your own 4 to 5 digit port number (49151 is the highest port number)

Uncomment and change

#Protocol 2, 1

to

Protocol 2

Uncomment and change

#ListenAddress 0.0.0.0

to

ListenAddress 198.32.64.12 (use one of your own IP Addresses that has been assigned to your server)

If you would like to disable direct Root Login, go to:

#PermitRootLogin yes

and uncomment it and make it look like

PermitRootLogin no

Now restart SSH

# /etc/rc.d/init.d/sshd restart

Exit out of SSH, and then re-login to SSH using the new IP , and the new port.

If you should have any problems, just Telnet into your server, fix the problem, then SSH in again. Telnet is a very unsecure protocol, so change your root password after you use it.

Disable Telnet

# vi /etc/xinetd.d/telnet

change disable = no to disable = yes

Save and Exit

# /etc/init.d/xinetd restart

Server e-mail everytime someone logs in as root:

If you want notification when someone logs in as root, SSH into server and login as root.

# vi .bash_profile

Go to end of the file and add the following line:

echo ‘ALERT – Root Shell Access on:’ `date` `who` | mail -s “Alert: Root Access from `who | awk ‘{print $6}’`” [email protected]

To Set an SSH Legal Message

# vi /etc/motd

Enter your message, save and exit.

You can use following message.

“This system is restricted to authorized access only. All activities on
this system are recorded and logged. Unauthorized access will be fully
investigated and reported to the appropriate law enforcement agencies.”

Latest posts by Sam (see all)

Sharing

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.