Question : How is the local port number allocated when connecting to a remote server via ssh

Hi All,

When I connect to a remote host via ssh, I use:
  ssh -x -v

I then get this line of output (amongst others):
  debug: Allocated local port 837
(The port number is different every time)

How does my local system allocate this port number?

Once I've logged into the remote system, I check this with netstat -an, and "Local Address" is using port 22 and "Remote Address" is using 837.

Is it random, next available or does each protocol have a set range of local ports it can use?

Thank you.

Answer : How is the local port number allocated when connecting to a remote server via ssh

From port allocated it is obvious that you run ssh as root, which is bad security practice.

Windows since 3.11 allocates TCP source ports in range 1024 till 5000 in order.
Modern operating systems chooses randomly.

Ports <1024 are reserved and allocated by root user, not by normal users to not interfere with system services.

This is not SSH specific, consult your systems documentation and sources about ephemeral port allocation.
Random Solutions  
 
programming4us programming4us