I want to change my ssh port from 22 to something else. What is the port range I can change it to? Also, I don't want it to conflict with other apps that use common ports. What ports should I avoid?
The other answers mistakenly seem to suggest that it is OK to use a service port which isn't used on your machine (as seen from the output of
nmap localhost). It is not! This because:
- if you add that particular service later, it's going to conflict with the SSH server and you're going to be into trouble, and
- services that run on another registered service port are guaranteed to cause confusion.
For instance in Mohsen's output there is no service running on TCP port 143 so you might think that you could use that port for your SSH server. However, the day you also install a IMAP mailserver, it will conflict with it.
You should run SSH on an unprivileged port number, i.e. from 1024 to 65535, and avoid IANA registered service numbers (you can get the same list via the shell command
It is usually also a good idea to choose a new port number that reminds the original port; for instance, in this case, 10022 or 22022.
You can choose any other port to your liking, e.g. anything between 0 and 65535 (0 … 2¹⁶-1).
You can get the information for registered ports from
/etc/services or something like wikipedia.
It's related to your machine, Suppose :
root@debian:/home/mohsen# nmap localhost Starting Nmap 6.47 ( http://nmap.org ) at 2015-04-16 04:57 IRDT Nmap scan report for localhost (127.0.0.1) Host is up (0.000025s latency). Other addresses for localhost (not scanned): 127.0.0.1 Not shown: 991 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 25/tcp open smtp 80/tcp open http 81/tcp open hosts2-ns 631/tcp open ipp 3306/tcp open mysql 5432/tcp open postgresql 9050/tcp open tor-socks
If you want to change port 22 to 9050 , you have conflict.
Ports have been assigned by IANA you can view