How do I change my SSH *outgoing* port on OSX?

1

Trying ssh -p 51685 seems to change the port that I'm trying to connect to, not my outgoing port.

As does editing ssh_config.

I want to change my outgoing port from 22 (which is blocked) to 51685.

Any ideas?

AP257

Posted 2011-02-25T13:19:58.703

Reputation: 195

Maybe I'm missing something obvious, but what is wrong with the two approaches you list yourself? – a CVn – 2011-02-25T13:30:17.767

@Michael: the two methods he lists change the destination port, not the source port. – David Spillett – 2011-02-25T14:01:54.883

3Odds are, the corporate firewall you're trying to circumvent is doing packet inspection and is blocking traffic DESTINED for 22. See Dave's answer below. – peelman – 2011-02-25T16:01:10.640

Answers

5

Outgoing connections do not use fixed port assignments, they choose an available port number, usually higher than 1024. More to the point, unless you are running as root (the admin user account, which is disabled by default on OSX), you cannot open an outgoing connection on port 22 because only root is allowed to open any ports below 1024. Therefore, if you're running ssh and are not root at the time, you're definitively not using port 22 for outgoing connections.

Whatever issue you're having, you have incorrectly identified its cause.

Dave Sherohman

Posted 2011-02-25T13:19:58.703

Reputation: 5 143

1

Are you sure it is the source port that is being filtered? Clients usually use an arbitrary source port (between 1024 and 65535) not the protocol's assigned port, and if your connection passes through any NAT arrangements on the way between you and the server (or the device that is doing the blocking) the original source port will be "lost" anyway so source port based filtering isn't usually very useful anyway.

For instance I've just made a fwe connections using PuTTY and OpenSSH to one of my servers, and wireshark tells me that the source ports for the connections where 6525, 6535, 6560 and 6562.

David Spillett

Posted 2011-02-25T13:19:58.703

Reputation: 22 424