简体   繁体   English

更改默认端口(22)SSh [CENTOS]

[英]Change the default port(22) SSh [CENTOS]

I am trying to change d default port (22) for my system, I edited the sshd_config file by changing to my desirable port no (5555) and restarted my service but it seem not to work . 我正在尝试为系统更改默认端口(22),通过更改为所需的端口号(5555)编辑了sshd_config文件,然后重新启动了服务,但它似乎无法正常工作。 is there something else i have to change? 还有什么我需要改变的吗? thanks 谢谢

Yes, you must allow that new port in iptables. 是的,您必须在iptables中允许该新端口。 iptables is the firewall program for Linux. iptables是Linux的防火墙程序。

With root privileges you will need to do this: 具有root特权,您将需要执行以下操作:

iptables -I INPUT 1 -p tcp  --dport 5555 -j ACCEPT  

Make sure you can connect using port 5555 then disable the old port. 确保可以使用端口5555连接,然后禁用旧端口。

iptables -A INPUT -j DROP -p tcp --dport 22

then save the new settings 然后保存新设置

/etc/init.d/iptables save

Check out this really good webpage for more information: 查看这个非常好的网页以获取更多信息:

http://www.rackspace.com/knowledge_center/article/introduction-to-iptables#Save_Save_Save_your_Ruleset http://www.rackspace.com/knowledge_center/article/introduction-to-iptables#Save_Save_Save_your_Ruleset

1) Make a backup of the sshd config file (optional but a good idea): 1)备份sshd配置文件(可选,但这是个好主意):

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

2) edit the sshd_config file to include your alternate port 2)编辑sshd_config文件以包含备用端口

vi /etc/ssh/sshd_config

Leave the default port 22 active for now and add your custom port 现在让默认端口22保持活动状态并添加自定义端口

# Open ports for sshd
Port 22
Port 5555

3) Open the custom port in your firewall 3)在防火墙中打开自定义端口

iptables -I INPUT 1 -p tcp  --dport 5555 -j ACCEPT  
service iptables save

4) Use a new terminal window to make sure you can login with your custom port 4)使用新的终端窗口来确保您可以使用自定义端口登录

ssh -p 5555 myuser@myserver.com

If this doesn't work, now you can still login on port 22 to troubleshoot 如果这不起作用,现在您仍然可以登录端口22进行故障排除

5) Once you've confirmed the custom port works, edit the sshd_config file and firewall settings to block port 22 5)确认自定义端口有效后,编辑sshd_config文件和防火墙设置以阻止端口22

vi /etc/ssh/sshd_config

... ...

# Open ports for sshd
# Port 22
Port 5555

... ...

iptables -A INPUT -j DROP -p tcp --dport 22
service iptables save

Now you'll want to test again to make sure you can login with your custom port but not with the default port of 22. 现在,您需要再次测试以确保您可以使用自定义端口登录,但不能使用默认端口22登录。

You will need to have root privileges or use sudo for the above commands. 您将需要具有root特权或对以上命令使用sudo

Step - 1: 第1步:

  nano /etc/ssh/sshd_config

and change the port from 22 to the desired one ie 5555 并将端口从22更改为所需的端口,即5555

  service sshd restart

Step - 2: 第2步:

 nano /etc/sysconfig/iptables

Here, you will find an entry for port 22. You will need to change it to 5555 在这里,您将找到端口22的条目。您需要将其更改为5555。

  service iptables restart

Now, try the SSH using, 现在,尝试使用SSH,

 - ssh -p 5555 root@Your IP Address

To Change the SSH Port for Your Linux Server 更改Linux服务器的SSH端口

  1. Connect to your server via SSH 通过SSH连接到服务器

  2. Switch to the root user 切换到root用户

  3. Run the following command: 运行以下命令:

     vi /etc/ssh/sshd_config 
  4. Locate the following line: #Port 22 找到以下行: #Port 22

  5. Remove # and change 22 to your desired port number like 2224 etc. 删除#并将22更改为所需的端口号,例如2224等。

  6. Restart the sshd service by running the following command: 通过运行以下命令来重新启动sshd服务:

     service sshd restart 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM