Changing SSH port in Ubuntu or Debian

Karikevinod
1 min readAug 24, 2020

SSH or Secure Command is a network protocol, that helps to connect and perform operation in the remote machine. You can connect to SSH with key or username and password.

Image courtesy

By default SSH uses port 22. You may need to change the ssh port for security security reasons such as to avoid targets from bots. You can change the default port by below steps.

  • Login to the server/remote machine
  • Open /etc/ssh/sshd_config
  • Locate the text: Port 22
  • Change the port which you want to set. Choose a port between 1024 and 65535.
  • Save the file and exit
  • Restart the ssh service: sudo systemctl restart sshd
  • Disconnect from the server
  • Now, connect to machine with specifying new port as SSH is not utilising default port. Use code as below to ssh into the machine.
ssh -p 12174 ubuntu@192.168.0.58scp -P 12174 file.zip ubuntu@192.168.0.58

Note: -p is used for ssh and -P is used for scp to specify the port

--

--

Karikevinod

Start-up and tech enthusiast. I write about Tech, Devops and anything related.