Linux修改SSH端口
SSH(Secure Shell)是一种加密的网络协议,可以通过远程连接方式管理服务器。默认情况下,SSH端口是22。由于安全方面的考虑,建议用户修改SSH端口号,增强服务器安全性。下面给出两种常见的修改SSH端口的方法。
方法一:通过修改SSH配置文件
1. 打开SSH配置文件/etc/ssh/sshd_config。
2. 使用文本编辑器,如vi或nano,编辑sshd_config文件。
3. 找到"Port"行,把22修改成任意未被占用的端口号,如12345。
4. 保存修改并退出编辑器。
5. 重新启动SSH服务,使修改生效。命令为:service ssh restart。
注意:如果使用防火墙,需要打开修改后的SSH端口。
方法二:通过命令行修改SSH端口号
1. 登录服务器。
2. 执行sudo命令,以root权限修改SSH配置文件/etc/ssh/sshd_config。例如:sudo vi /etc/ssh/sshd_config。
3. 找到"Port"行,把22修改成任意未被占用的端口号,如12345。
4. 保存修改并退出编辑器。
5. 重新启动SSH服务,使修改生效。命令为:sudo service ssh restart。
注意:如果使用防火墙,需要打开修改后的SSH端口。
Conclusion
SSH端口是服务器安全中非常重要的一部分,通过修改SSH端口可以加强服务器的安全性。本文介绍了两种修改SSH端口的方法,用户可以根据自己的需要进行选择。同时,为了保证服务器的安全性,建议定期修改SSH端口号。
Linux Modify SSH Port
SSH (Secure Shell) is an encrypted network protocol that enables remote management of servers. By default, the SSH port is 22. For security reasons, it is recommended to change the SSH port number and enhance the server's security. Here are two common ways to modify the SSH port.
Method one: Modify SSH configuration file
1. Open SSH configuration file /etc/ssh/sshd_config.
2. Use a text editor, such as vi or nano, to edit the sshd_config file.
3. Find the "Port" line and change 22 to any unused port number, such as 12345.
4. Save the changes and exit the editor.
5. Restart the SSH service to make the changes take effect. The command is: service ssh restart.
Note: If a firewall is used, the modified SSH port needs to be opened.
Method two: Change SSH port number via command line
1. Log in to the server.
2. Execute the sudo command to modify the SSH configuration file /etc/ssh/sshd_config with root privileges. For example, sudo vi /etc/ssh/sshd_config.
3. Find the "Port" line and change 22 to any unused port number, such as 12345.
4. Save the changes and exit the editor.
5. Restart the SSH service to make the changes take effect. The command is: sudo service ssh restart.
Note: If a firewall is used, the modified SSH port needs to be opened.
Conclusion
The SSH port is a crucial part of server security. Modifying the SSH port can enhance the security of the server. This article introduces two methods of changing the SSH port. Users can choose the method that suits their needs. To ensure the security of the server, it is recommended to regularly change the SSH port number.
评论前必须登录!
注册