This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15354|Reply: 1

[linux] LINUX modifies the default SSH method of port 22

[Copy link]
Posted on 10/7/2014 10:58:24 PM | | |

The first type: 01 If you want to change the default port (22) of Linux SSH, then you only need to modify Port 22 in /etc/ssh/sshd_config, here you can change 22 to the port you want to set, but don't set it to the same port as the existing one, to prevent unknown consequences.

02 If you want to restrict SSH login IPs, you can do the following:

First: Modify /etc/hosts.deny and add sshd:ALL to it

Then: Modify: /etc/hosts.allow, where you can set the following settings: sshd:192.168.0.241

This restricts only 192.168.0.241 IPs from logging in to LINUX machines via SSH. Of course, as a server, I don't install gnome and KDE, and many dongdong don't install it, so as to increase the security factor.

Second: First modify the configuration file vi /etc/ssh/sshd_config

Find the #Port 22 paragraph, here is the default use of port 22, modified to the following:

Port 22 Port 50000 then save and exit

Perform /etc/init.d/sshd restart so that the SSH port will work with 22 and 50000 at the same time.

Now edit the firewall configuration: vi /etc/sysconfig/iptables

50000 ports are enabled.  Perform /etc/init.d/iptables restart

Now use the ssh tool to connect port 50000 to test if it is successful. If the connection is successful, edit the sshd_config settings again and delete the port22 inside.

The reason why it is set to two ports first, and then one port is closed after the test is successful, is to modify the conf, in case there is an unknown situation such as disconnection, network disconnection, misoperation, etc., you can also connect to another port to debug to avoid the need to send someone to the computer room to avoid the connection failure, resulting in more complex and troublesome problems.






Previous:Tutorial on expanding the capacity of the system disk to the C drive and increasing the disk size
Next:I'm going to see if I can build a VPN for everyone to use for free
 Landlord| Posted on 10/7/2014 11:00:49 PM |
The command line is changed to the default port 22
1. The /etc/ssh/sshd_config file is modified

[root@linux ~]# vi /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.69 2004/05/23 23:59:53 dtucker Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
Port 8284 // Previously, this one had a # number in front of it, and the default was 22, just modify it
#Protocol 2,1
#ListenAddress 0.0.0.0
#ListenAddress ::
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
2. Restart the ssh service and modify the port to take effect
[root@linux ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@linux ~] #
3. In order to check whether it is correct, you can use the netstat -an command to check.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com