arrow_upward

Pages (2):
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change SSH port in VPS
#1
Hello Folks. Last time I went to login to my VPS but I found a very weird thing, check the ping below.

[Image: 1505290836.png]

So someone was brute forcing my VPS and as you can see 22082 failed login so you have to take an action and do something before accessing your VPS so I found the solution for this and that solution was Changing SSH Port and that's going to be our tutorial for today.

So firstly you have to install nano using this command

On Ubuntu

sudo apt-get install nano


On CentOS and Fedora

sudo yum install nano


Then we have to type this command to edit the SSH settings [Works for all Linux Distributions]
nano /etc/ssh/sshd_config

Then you will find

#Port 22


You have to uncomment it and change the port, for example it's going to be like that

Port 55


Now save your changes and now we are done, last command we have to execute only to restart the SSH service.

Use this command if you are using Ubuntu

service ssh reload


And use this command if you are using CentOS or any Redhat Distribution

sudo systemctl restart sshd


Now we are done. Your connection will not be disconnected but next time you wanna to connect you have to put the port you chose in the port box (for me it was 55) like that
[Image: 1505293072.png]

And if you are using Linux so you have to type

ssh root@MyVPSIP -p 55
root = The VPS User
MyVPSIP = The IP of your VPS
-p = Means to use specific port
55 = Is the port I chose

The whole command means to connect to my VPS using a user called root in this IP and use specific port which it's 55.

That was our small tutorial for today, it seems too tall but it's so easy also I advise you to change the VPS port for not getting brute force or attacks on this port.
Thank you for reading my small tutorial, I hope you benefited from it and goodbye. Angel
#2
Depending of what Linux version you are using
you can do a search on google
but if you are using Cent OS Linux, try following the below instructions


1: Login with the root user name and password
-su

2: Backup the ssh config file
-sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

3: Edit the ssh config file
-sudo vi /etc/ssh/sshd_config

4: press insert key to begin the edit of the file
5: scroll down to #Port 22 - and enter the port number you wish you use - make sure to remove # after editing
6: type: ":wq" to save the changes and press: "ENTER" to confirm

7: Next install the python config
-sudo yum -y install policycoreutils-python

8: reenter the new port is here
-sudo semanage port -a -t ssh_port_t -p tcp "ENTER THE TCP PORT HERE FROM STEP 5"

9: Next check the firewall
-sudo firewall-cmd --permanent --zone=public --add-port="ENTER THE TCP PORT HERE FROM STEP 5"/tcp
-sudo firewall-cmd --reload

10: now restart the SSH services
-sudo systemctl restart sshd.service

11: Now the new port has been configured -
ss -tnlp | grep ssh

12: if you would like to rollback the change from steps 1 - 10
IN THE CASE SSH ISNT WORKING ANYMORE
you may need to Reinstall the SSH services - USING THIS COMMAND
-yum -y install openssh-server openssh-clients

Hope this help and please provide me your feedback.
#3
(09-13-2017, 11:38 AM)Liquidips Wrote: Depending of what Linux version you are using
you can do a search on google
but if you are using Cent OS Linux, try following the below instructions


1: Login with the root user name and password
-su

2: Backup the ssh config file
-sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

3: Edit the ssh config file
-sudo vi /etc/ssh/sshd_config

4: press insert key to begin the edit of the file
5: scroll down to #Port 22 - and enter the port number you wish you use - make sure to remove # after editing
6: type: ":wq" to save the changes and press: "ENTER" to confirm

7: Next install the python config
-sudo yum -y install policycoreutils-python

8: reenter the new port is here
-sudo semanage port -a -t ssh_port_t -p tcp "ENTER THE TCP PORT HERE FROM STEP 5"

9: Next check the firewall
-sudo firewall-cmd --permanent --zone=public --add-port="ENTER THE TCP PORT HERE FROM STEP 5"/tcp
-sudo firewall-cmd --reload

10: now restart the SSH services
-sudo systemctl restart sshd.service

11: Now the new port has been configured -
ss -tnlp | grep ssh

12: if you would like to rollback the change from steps 1 - 10
IN THE CASE SSH ISNT WORKING ANYMORE
you may need to Reinstall the SSH services - USING THIS COMMAND
-yum -y install openssh-server openssh-clients

Hope this help and please provide me your feedback.

Very nice but I have done all this in 3 commands only and no need to reinstall the SSH service or checking the firewall or anything else. Btw thank you for additional, my tutorial might doesn't work with some people so they may try yours. Big Grin
#4
Can you please tell also how to change Host/username of vps? and how to add custom domain name as a vps host name ?
Heart LOVE FOR ALL  HATRED FOR NONE Heart
#5
(09-14-2017, 04:16 AM)sagher Wrote: Can you please tell also how to change Host/username of vps? and how to add custom domain name as a vps host name ?

Do you mean VPS hostname which it's located inside the VPS like [root@amir ~] or the reverse DNS (rDNS)? Also do you mean to host a domain on the VPS right? Please explain more to be able to benefit you. Big Grin
#6
(09-13-2017, 03:03 PM)AmirGT Wrote: Very nice but I have done all this in 3 commands only and no need to reinstall the SSH service or checking the firewall or anything else. Btw thank you for additional, my tutorial might doesn't work with some people so they may try yours. Big Grin

I think that he is checking if the someone who is trying to login made a thing and etc. 
And thats not bad as we can know if the person caused any diseases at the vps server.
Right? @Liquidips ?
#7
(09-14-2017, 11:11 AM)youssefbasha Wrote: I think that he is checking if the someone who is trying to login made a thing and etc. 
And thats not bad as we can know if the person caused any diseases at the vps server.
Right? @Liquidips ?

No, he just added an exception to the VPS firewall to allow him connecting the specified port which he chose above.
#8
(09-14-2017, 09:01 AM)AmirGT Wrote: Do you mean VPS hostname which it's located inside the VPS like [root@amir ~] or the reverse DNS (rDNS)? Also do you mean to host a domain on the VPS right? Please explain more to be able to benefit you. Big Grin

Yes the first one you explain . i go to hostname and edit it but i can't succeed. [root@amir ~]  which file i need to edit and which ssh command do my favor.
Heart LOVE FOR ALL  HATRED FOR NONE Heart
#9
(09-14-2017, 11:42 AM)sagher Wrote: Yes the first one you explain . i go to hostname and edit it but i can't succeed. [root@amir ~]  which file i need to edit and which ssh command do my favor.

You can simply change it from the VPS control panel you will fine an option called "Hostname" you can try it. Or you can try one of these tutorial
https://rimuhosting.com/howto/hostname.jsp
https://support.rackspace.com/how-to/cen...me-change/
#10
(09-14-2017, 01:12 PM)AmirGT Wrote: You can simply change it from the VPS control panel you will fine an option called "Hostname" you can try it. Or you can try one of these tutorial
https://rimuhosting.com/howto/hostname.jsp
https://support.rackspace.com/how-to/cen...me-change/

Service provider can not gives me control panel. thats why i rely on ssh putty.
Heart LOVE FOR ALL  HATRED FOR NONE Heart
Pages (2):


Possibly Related Threads…
Thread
Author
Replies
Views
Last Post
2,943
11-03-2019, 02:31 AM
Last Post: tiwil

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting