Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section General Discussion
  • Search

Changing SSH port

General questions about VestaCP
Post Reply
  • Print view
Advanced search
12 posts
  • 1
  • 2
  • Next
durjoy
Posts: 66
Joined: Thu Oct 16, 2014 12:56 pm

Changing SSH port
  • Quote

Post by durjoy » Mon Nov 10, 2014 2:26 pm

Hi
I am planning to change SSH port on all of my VPS for security reason.
I know new version of vestaCP comes with fail2ban and IPtable.
I don't want my IP address to get banned for failed login attempt.

How can I add new SSH port to IPTable and VestaCP.
what command shall I enter and what file shall I modify?

thanks
Top

Milka
Posts: 137
Joined: Tue Feb 11, 2014 2:03 pm

Re: Changing SSH port
  • Quote

Post by Milka » Mon Nov 10, 2014 3:04 pm

You should first allow the port (and maybe also your home/office IP) in Vesta, otherwise you'd lock yourself out. You can do that in Vesta's web interface. Then you can edit /etc/ssh/sshd_config to change the port. Don't forget to restart ssh (service sshd restart) to apply your changes.
Top

Trentor
Posts: 84
Joined: Fri Apr 25, 2014 6:42 pm

Re: Changing SSH port
  • Quote

Post by Trentor » Mon Nov 10, 2014 10:23 pm

1. Decide which port you want to use to connect your server via SSH (for this example, 19).

2. In Vesta panel, under Firewall menu, modify the SSH entry and put the new port number. With that, the iptables will be properly modified.

Image

3. Modify SSH config (use nano, vim, or your preferred text editor):

Edit the file:

Code: Select all

nano /etc/ssh/sshd_config

Search for:

Code: Select all

#Port 22
And change it:

Code: Select all

Port 19
Save the file.

4. We are going now to modify your fail2ban to add your IP to the whitelist.

Edit the file:

Code: Select all

nano /etc/fail2ban/jail.local
Search for:

Code: Select all

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8
Add your IP at the end of the block:

Code: Select all

ignoreip = yo.ur.ip
Save the file.

5. Restart the modified services:

Restart SSH (use the correct command for your distro, for this example, CentOS):

Code: Select all

service sshd restart
Restart iptables:

Code: Select all

service iptables restart
Restart fail2ban:

Code: Select all

service fail2ban restart
Done.
Top

durjoy
Posts: 66
Joined: Thu Oct 16, 2014 12:56 pm

Re: Changing SSH port
  • Quote

Post by durjoy » Tue Nov 11, 2014 1:00 am

You guys are legends. thank you for all the help.
Top

pandabb
Posts: 192
Joined: Sat Aug 08, 2015 3:03 am

Re: Changing SSH port
  • Quote

Post by pandabb » Sat Aug 08, 2015 6:59 am

Hello guys, can i ask if i did the right thing?

I did the same above except that my ip is dynamic so what i did is converted my iprange to cidr using online site generators.

Will that work too?

TY
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Changing SSH port
  • Quote

Post by skurudo » Tue Aug 11, 2015 9:15 am

pandabb wrote: I did the same above except that my ip is dynamic so what i did is converted my iprange to cidr using online site generators.
Will that work too?
Yep
ignoreip = 127.0.0.1 192.168.1.0/24 8.8.8.8
http://www.fail2ban.org/wiki/index.php/Whitelist
Top

pandabb
Posts: 192
Joined: Sat Aug 08, 2015 3:03 am

Re: Changing SSH port
  • Quote

Post by pandabb » Tue Aug 11, 2015 11:27 am

Thank again for the answer.

The guide shown in this thread suggest editing /etc/fail2ban/jail.local howerver in that section i cannot find the entry below:

Code: Select all

# This will ignore connection coming from common private networks.
# Note that local connections can come from other than just 127.0.0.1, so
# this needs CIDR range too.
ignoreip = 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
I found on it jail.conf instead of jail.local

Ty


i edited mine in jail.conf since its not found on jail.local , is that OK?
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Changing SSH port
  • Quote

Post by skurudo » Tue Aug 11, 2015 10:16 pm

By default settings in /etc/fail2ban/jail.conf, but there is and local file, where setting are too.

Every .conf file can be overridden with a file named .local. The .conf file is read first, then .local, with later settings overriding earlier ones. Thus, a .local file doesn't have to include everything in the corresponding .conf file, only those settings that you wish to override.
Modifications should take place in the .local and not in the .conf. This avoids merging problem when upgrading. These files are well documented and detailed information should be available there.
-- http://www.fail2ban.org/wiki/index.php/ ... l_settings
Top

pandabb
Posts: 192
Joined: Sat Aug 08, 2015 3:03 am

Re: Changing SSH port
  • Quote

Post by pandabb » Wed Aug 12, 2015 7:40 am

Hi thanks i didnt know that.

By default i alraedy have jail.local what i did is add the whitelist ip at the very end, is this ok?

this is how it looks likes now.

Code: Select all

[ssh-iptables]
enabled  = true
filter   = sshd
action   = vesta[name=SSH]
logpath  = /var/log/secure
maxretry = 5

[vsftpd-iptables]
enabled  = false
filter   = vsftpd
action   = vesta[name=FTP]
logpath  = /var/log/vsftpd.log
maxretry = 5

[exim-iptables]
enabled = true
filter  = exim
action  = vesta[name=MAIL]
logpath = /var/log/exim/main.log

[dovecot-iptables]
enabled = true
filter  = dovecot
action  = vesta[name=MAIL]
logpath = /var/log/dovecot.log

[mysqld-iptables]
enabled  = false
filter   = mysqld-auth
action   = vesta[name=DB]
logpath  = /var/log/mysqld.log
maxretry = 5

[vesta-iptables]
enabled = true
filter  = vesta
action  = vesta[name=VESTA]
logpath = /var/log/vesta/auth.log
maxretry = 5

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8 MY IP ADDRESS HERE
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Changing SSH port
  • Quote

Post by skurudo » Wed Aug 12, 2015 7:44 am

pandabb wrote: this is how it looks likes now.
Look nice.
Top


Post Reply
  • Print view

12 posts
  • 1
  • 2
  • Next

Return to “General Discussion”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password