SSH


change SSH port

ssh root@192.168.0.1 -p 2244  OR  ssh root@hostname  -p2200

yum –y install openssh-server openssh-clients

systemctl restart sshd

systemctl enable sshd

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

Managed & Fully Managed Linux Servers

 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--------------------------------------------


[root@mail ~]# grep Port /etc/ssh/sshd_config#Port 22Port 7575#GatewayPorts no
Check the SSH Port[root@mail ~]# netstat -plntu | grep sshtcp        0      0 0.0.0.0:7575            0.0.0.0:*               LISTEN      165542/sshd         tcp6       0      0 :::7575                 :::*                    LISTEN      165542/sshd 

[root@mail ~]# netstat -an | grep 7575tcp        0      0 0.0.0.0:7575            0.0.0.0:*               LISTEN     tcp        0      0 192.168.117.2:7575      192.168.117.142:56396   ESTABLISHEDtcp        0    200 203.76.150.58:7575      202.161.189.29:58750    ESTABLISHEDtcp6       0      0 :::7575                 :::*                    LISTEN     unix  2      [ ACC ]     STREAM     LISTENING     1837575899 /var/run/dovecot/auth-workerunix  2      [ ACC ]     STREAM     LISTENING     1837575903 /var/run/dovecot/anvilunix  2      [ ACC ]     STREAM     LISTENING     1837575907 /var/run/dovecot/anvil-auth-penaltyunix  2      [ ACC ]     STREAM     LISTENING     1837575910 /var/run/dovecot/masterunix  2      [ ACC ]     STREAM     LISTENING     1837575896 /var/spool/postfix/private/auth

The Port You’re Trying to Use-SSH service is listening
# lsof -i -n -P | grep LISTEN# lsof -i -P -n | gre ssh



Enjoy!

----------------------