Faruque Ahmed : MCP, MCSA, MCSE, MCTS, MCIT, CCNA, OCA, OCP, GCP
change SSH port
SSH-Port
# grep -R ^Port /etc/etc/ssh/sshd_config:Port 22System/well known ports: 0-1023
User or registered ports: 1024-49151
Dynamic/private ports: 49152-65535
# yum –y install openssh-server openssh-clients
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.BK
# vi /etc/ssh/sshd_config
----------------------------------
# If you want to change the port on a SELinux system, you have to tell# SELinux about this change.# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER#Port 2244
#AddressFamily any#ListenAddress 0.0.0.0#ListenAddress ::---------------------------------
firewall-cmd --permanent --zone=public --add-port=2244/tcp
sudo firewall-cmd --reload
# systemctl restart sshd.service
# service sshd restart
Verify that SSH is now running on the new port by running the commands below.
ss -tnlp | grep ssh
LISTEN 0 128 *:2244 *:* users:((“sshd”,10783,3))
LISTEN 0 128 :::2244 :::* users:((“sshd”,10783,4))
-----------------------------
ssh root@192.168.0.1 -p 2244
SSH/Telnet Check
UseDNS no
sudo su -
su -
Error
SSH fails after Port change on CentOS 7
systemctl status sshd.service
sshd.service: main process exited, code=exited, status=255/n/a Unit sshd.service entered failed state. sshd.service failed.
# vi /etc/ssh/sshd_config
-------------------------
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
Port 2244
#AddressFamily any
----------------------
Save the file.
# semanage port -a -t ssh_port_t -p tcp 2244
If you run the commands above and get an error that semanage command not found, run the commands below to install it.
# yum -y install policycoreutils-python
.Verify it's allowed now:
# semanage port -l | grep ssh
Firewall.
# firewall-cmd --permanent --zone=public --add-port=2244/tcp
Reload the firewall configurations
# firewall-cmd --reload
Restart SSH by running the commands below.
# systemctl restart sshd.service
Verify that SSH is now running on the new port by running the commands below.
# ss -tnlp | grep ssh
LISTEN 0 128 *:2244 *:* users:((“sshd”,10783,3))
LISTEN 0 128 :::2244 :::* users:((“sshd”,10783,4))
Exit and try signing in using the new port number.
ssh root@192.168.0.1 -p 2244
Step 4: Connect to SSH server on port # 2022 using SSH command:
ssh -p PortNumberHere user@server-name-here
ssh -p PortNumberHere user@server-name-here commandNameHere
ssh -p 2022 XYZ@192.168.1.5
ssh -p 2022 XYZ@192.168.1.5 df
To connect to an SSH server on port # 2022 using scp command type:
scp -P PortNumberHere source user@server-name-here:/path/to/dest
scp -P 2022 resume.pdf XYZ@nas01:/backups/personal/XYZ/files/
To connect to an SSH server on port # 2022 using sftp command type:
sftp -P PortNumberHere user@server-name-here
sftp -P 2022 XYZ@192.168.1.5
To connect to SSH server on port # 2022 using rsync command type:
Change SSH port number with rsync command:
sync -av -e 'ssh -p PORT-NUMBER-HERE' source user@server-name
So, to backup /home/XYZ to server1.XYZ.net.in at port number 2022, enter:
rsync -av -e 'ssh -p 2022' /home/XYZ/ backupop@server1.XYZ.net.i
------------------------------Check--------------------------------------------
Enjoy!
----------------------