I have a Centos machine version centos-release-7-9.2009.1.el7.centos.x86_64. I am trying to change the sftp port, which is currently the default port 22. I was able to follow the article and was able to set sftp to port 22 and ssh to port 2222. I have existing users using the machine and this change will affect them. I am trying to set sftp on both 22 and 2222 port and keep ssh on port 22. Is it possible to do that by any means. I have searched online but could not find much help regarding that.
In my sshd_config I updated the following:
Port 22 #2222 added as extra argument to change sftp port Port 2222 # override default of no subsystems #Subsystem sftp /usr/libexec/openssh/sftp-server #custom value to change sftp port Subsystem sftp internal-sftp #extra arguments for port change Match LocalPort 22 AllowTCPForwarding no X11Forwarding no ForceCommand internal-sftp In my sshd_config file, if I just add the following:
Port 22 #2222 added as extra argument to change sftp port Port 2222 and none of the other changes above, I am able to connect ssh on two ports, but sftp only on 22. I am looking for exactly the other way, SSH on 22 and sftp on both 22 and 2222
11 Answer
Yes, it is possible. The simple Match condition of a port you should only use for the 2222 port - it's the one, where you want sftp only.
In the other rule, you need to specify not only port (this would kick out your regular users too), but also another condition (if there are some users or groups which are not to be allowed to use other possibilities besides the sftp).
As a man page clearly states: "If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file."