Friday, September 18, 2020

Setting a SSH server in a workstation



sudo apt install openssh-server

systemctl status sshd

sudo systemctl restart ssh

sudo ufw allow ssh

Enable the SSH server to start automatically during the boot.

sudo systemctl enable ssh

Connect from a remote client to your SSH server. First, obtain an IP address of your SSH server. 

ip a

If connecting over the internet you need your external IP address:

echo $(wget -qO - https://api.ipify.org)

Check if IP being used to login via SSH is correct. Re-check IP of device being SSH'd into with:

hostname -I

For Dynamic DNS the freedns.afraid.org works fine with ddclient in Linux.

If you don't want to use the default port 22 for SSH, you need to edit the sshd config file in:

/etc/ssh/sshd_config 

and change the value of "Port 22" in it for another number. You should run SSH on an unprivileged port number, i.e. from 1024 to 65535. You can check what local ports are in use currently to avoid a conflict with:

netstat -taulpn 

and also avoid IANA registered service numbers, check with:

cat /etc/services

Once you have made the appropriate change open a firewall port to correspond with the new SSH port where "xxxx" represent the new number that you chose:

sudo ufw allow xxxx/tcp

Then

sudo systemctl restart ssh

For a SSH connection through a specific port, where "xxxx" is the number chosen, do:

ssh -p xxxx username@{hostname or IP}



----