Help with changing SSH port

FileSick

Verified User
Joined
Oct 5, 2013
Messages
104
hello everyone

right now i was trying to edit my ssh port to reduce the brute force attack i'm getting a little bit but i never done it before and he is the issues i'm facing right now

first i can't edit the line port 22 to anything i want what ever i write next to it but nothing happens

after i edit the port to number to whatever number i want how to save the changes

now what to do in order to protect this new port with the firewall i am using which is csf

when to type the restart the ssh command

note : i am using centos

waiting for your respond
 
I've changed the thread subject line to make it easier for others to find it.

You need to edit the file from a root shell login using a shell-based file editor. If you do that you'll be able to save it.

When you change to a different port you'll need to remove the hash-mark (# sign) in front of the word Port.

Or you can leave the commente dout port 22 lina (it's just there to show you the default) and put in your own line underneath it witout the # mark.

You MUST disable the firewall or change it before you restart your sshd, or you'll risk losing acces to your server. But if you're using CSF Firewall this may not be as much of an issue because you can change the configuration from DirectAdmin login.

From CSF Fireall administration screen choose Firewall Configuration button, then search for:

Allow incoming TCP ports
Allow outgoing TCP ports

and in each of these, add the port to which you're changing.

Save these changes and click on Restart csf+lfd[ when prompted.

Then restrt sshd, and make sure you can login (to another shell instance). Check to be sure you're able to login oin the new port but not on the old.

Once you're sure you can edit CSF again as above, to remove port 22 from the Incoming list, but you should probably leave it in the Outgoing list so you can at some point in the future shell into other servers (which use port 22) from this server.

Note I that mistakes cause big problems. While I believe my instructions above will work, I coule have made a mistake. I only guarantee work I do myself on your server, not answers given on these forums. If you'd like to hire me to do this for you, contact me by email at the email address below in my siglines. Or find someone else to do it for you.

Jeff
 
thank you so much for your help and time that really helped me out i changed the port and everything is working just fine
 
Back
Top