How to change the default SSH port?

Harry P

New member
Joined
Feb 3, 2015
Messages
331
Points
0
I want to change port 22 when login with SSH for my VPS? Please share your easiest ways?
 

RDO Servers

New member
Joined
Apr 3, 2015
Messages
770
Points
0
I want to change port 22 when login with SSH for my VPS? Please share your easiest ways?
- Connect to your server via SSH
- Switch to the root user (sudo su -)
Run vi /etc/ssh/sshd_config
Find where it says # Port 22
Remove # and change 22 to your desired port number.
Run service sshd restart
 

laceibanet

New member
Joined
Feb 23, 2016
Messages
43
Points
0
Log into your server as the root user.
Remove the number-sign (#) and change the value for the line.
For example, the default SSH port appears in a line like this:

#Port 22
To change the SSH port to 123, you will need to make the line appear like this:

Port 123
Update IPTables and Firewall

Any changes will also change your server's iptables and may overwrite any manual changes made directly to the iptables file itself.
After you are finished configuring SSH, you will need to add the port to iptables as well as your installed firewall.

To update iptables, please enter the following in SSH:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT
When using the command above, be sure to substitute 123 with the actual port number you are adding.

Reset SSH Daemon

After making the necessary changes to iptables and your computer's firewall, you will need to restart the SSH daemon. You can do it by entering this command:

/etc/init.d/sshd restart
Log out of your server and log in again using the proper user, IP address and port number you specified in sshd_config.
 

ElixantTechnology

New member
Joined
Nov 26, 2014
Messages
622
Points
0
As mentioned above, ensure that the port is open on the firewall! Also, before disconnecting create a second connection ensuring that you don't lock yourself out. Better safe than sorry right?
 
Recommended threads
Replies
17
Views
7,282
Replies
0
Views
2,669
Replies
3
Views
738
Replies
4
Views
7,608

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top