Benches macOS

15

alternative ports during SSH with terminal

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have used Putty to configure networks in the past, but the Windoze machine my company provided lost a HD and I wanted to try to use my Mac and Terminal to do the same thing. I was able to log into our server by using ssh root@<ip address>, but when I attempted to log into the directory, my password was refused and I suspect it was because the port used should have been 2022, not the default of 22. How do I assign that port when I log into the directory at the ip adress? Is it ssh root@<ip address>:<port> or some other format?

I have browsed and searched for an answer and did not see one on here, so if this is a duplicate, I apologize, but I did look. Thanks,

Message was edited by: twade1

15 replies

Sign in or join Beachball Help to reply.

  1. 0

    BobHarris

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    man ssh


    ssh -p 2022 [email protected]

  2. 0

    twade1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I really appreciate the quick response. I figured it was a really dumb of me, I must have been right!

  3. 0

    bsdbugler

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    If you don't feel like typing that out every time, create a .bashrc in your home directory and add this line:

    alias myhost='ssh -p 2020 my.host.dom'

    Then you can just type "myhost" to connect.

  4. 0

    foilpan

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    or define settings for that server in your ~/.ssh/config file, like so:


    Host hostname
    User admin
    Port 8822
    HostName server.company.com

    then just connect with "ssh hostname," and you're in.

  5. 0

    wgeck

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Port forwarding question. I have an Airport Extreme, and a computer accessing it via a static Ip.

    If I map the port: public TCP port 22 -> private (computer) port 22

    I can access my local computer remotely via ssh. (ssh [email protected])

    If I instead do: public TCP port 1122 -> computer's port 22

    I can not access the computer using "ssh -p 1122 [email protected]" I get a message "Connection timed out".

    If on my local machine, I execute this, I can connect. Just not remotely.

    Am I misunderstanding how port forwarding works?

    Thanks

    Message was edited by: wgeck

  6. 0

    foilpan

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    no, it should work. you might have better luck posting this separately in the airport extreme forum, though instead of in this thread.

    NAT should handle that easy port mapping, but i rarely use an airport for anything beyond simple base station duties. use a real firewall for NAT and the like.

  7. 0

    BobHarris

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hijacking someone else's thread, means you can not give anyone points for being helpful or for solving your problem.

    I do this with my Airport Extreme. I have several high numbered ports mapped to different home Macs local port 22.

    Since I have an ISP provided DHCP address, I use a No-IP.com dynamic DNS name so I can access my home router from coffee shops, hotels, and other open WiFi access points (DynDNS.org is a similar service).

    You can use something like Applications -> Utilities -> Network Utility -> Port Scan to verify that your port 1122 is open on your router.

    You can use


    ssh -v -v -v -p 1122 [email protected]

    where the -v -v -v will give you a lot more debugging information.

    If you perform 2 -v -v -v test, one with port 22 forwarded to port 22, and one with port 1122 forwarded to port 22, you can compare the 2 -v -v -v outputs and see where the failed ssh takes a sharp left turn 🙂 Where it goes bad, will help isolate what might be causing you problems.

  8. 0

    LittleSaint

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    This all makes sense for multiple NAT'ed PCs behind a firewall, but for a single PC there's really no point to changing the port for ssh unless you ISP blocks ssh. There's no security value to it. If you want to protect yourself secure your ssh service.

  9. 0

    BobHarris

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    There's no security value to it. If you want to protect yourself secure your ssh service.

    No, but there is a waste of your Mac's time factor when you open port 22 on the router's internet side.

    If you look at your console log when port 22 is open on your router, you will see constant knocking for common names, such as root, that your Mac needs to reject.

    By using a random high numbered port, the router gets to reject those connections, and your Mac can keep from adding tons of rejection entries to the logs, as well as spending CPU time doing it, and you disk will have a chance to spin down since it will not be written to every minute of the day and night.

    No it is not security, but it does cut down on the frequency of probe attempts on your ssh port.

  10. 0

    LittleSaint

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    For the most novice script kiddies sure, but anyone with a little knowledge will probe for open tcp ports first, and then initiate connections across anything that responds. In fact, using a port other than 22 might increase activity. I probably wouldn't bother trying to exploit port 22. An open, random high port might attract more attention.

  11. 0

    BobHarris

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Then again, I have my observed behavior vs your theory.

    I'm not saying using a high numbered port is security, only that it keeps the noise on the street down.

    Also using a port other than 22, is the only way to service multiple systems behind a home router.

    If you really want ssh security, you disable password logins and only allow ssh keys.

  12. 0

    wgeck

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Sorry for the thread hijack. Instead of creating a new thread, I used search to find something similar. I think I may need to start a thread in the Airport forum, though 😟 I don't think this is a Unix issue.

    When I connect on port 22, ssh -v -v -v gives a lot of detail, and is successful.

    If I use 1122, I get (replaced IP address):

    ssh -v -v -v -p 1122 [email protected]

    OpenSSH_5.4p1, OpenSSL 0.9.8n 24 Mar 2010

    debug2: ssh_connect: needpriv 0

    debug1: Connecting to 01.02.03.04 <01.02.03.04> port 1122.

    debug1: connect to address 01.02.03.04 port 1122: Connection timed out

    ssh: connect to host 01.02.03.04 port 1122: Connection timed out

    Using Network Utility/Port scan on the IP address shows:

    Open TCP Port: 1122 availant-mgr

    So, 1122 is open.

    However, when I use port 22 instead, it says:

    Open TCP Port: 22 ssh

    I don't know if that identifier (availant-mgr instead of ssh) is important.

    Message was edited by: wgeck

    Message was edited by: wgeck

  13. 0

    Charles Minow

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    LittleSaint wrote:

    using a port other than 22 might increase activity.

    That hasn't been my experience at all. I moved
    ssh to different port and never in the past six years has one single attempt been made against it. The kind of attacks where they try different ports and keep hammering away at a computer are not the kind of random attacks most people will see. If the idea is to use your computer for a DDOS or to serve up warez, which is what most attacks are, they'll just hit the usual vulnerabilities and move along if there's nothing obvious to exploit.

    charlie

  14. 0

    LittleSaint

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Well it's not a theory, but an observation from years of IDS analysis, but if it works for you that's fine. Home networks don't necessarily see the same patterns. As long as the practice isn't misinterpreted as real security, that's what's important.

  15. 0

    BobHarris

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I think I may need to start a thread in the Airport forum, though 😟 I don't think this is a Unix issue.

    Your right, this may be an Airport Extreme issue. Although, I do know it can work, as I have been port forwarding ssh using an Airport Extreme for several years. High several numbered ports to 22 on different Macs in my home.

    When I connect on port 22, ssh -v -v -v gives a lot of detail, and is successful.

    If I use 1122, I get (replaced IP address):

    ssh -v -v -v -p 1122 [email protected]

    OpenSSH_5.4p1, OpenSSL 0.9.8n 24 Mar 2010

    debug2: ssh_connect: needpriv 0

    debug1: Connecting to 01.02.03.04 <01.02.03.04> port 1122.

    debug1: connect to address 01.02.03.04 port 1122: Connection timed out

    ssh: connect to host 01.02.03.04 port 1122: Connection timed out

    OK, This might indicate that your Router port is Open, but the Mac on the other side is not answering the call. Either because the router did not pass it through properly, or because the Mac decided against it.

    As an example, if I choose a port that is NOT being forwarded, then, I get

    debug1: connect to address 1.2.3.4 port 1122: Connection refused

    I get the same error if I do not have Remote Login enabled.

    So I think your router has the port forwarded, and I think it is going to a port on your Mac that is listening for something, but for some reason it is not completing the login. Or the router is sending the port somewhere else that is accepting the input, but just not responding.

    This is most strange, since using port 22 -> 22 forwarding seems to work, which is why I'm wondering if it is actually getting to an sshd daemon on the Mac.

    Using Network Utility/Port scan on the IP address shows:

    Open TCP Port: 1122 availant-mgr

    So, 1122 is open.

    However, when I use port 22 instead, it says:

    Open TCP Port: 22 ssh

    I don't know if that identifier (availant-mgr instead of ssh) is important.

    Network Utility is just doing a simple number to name lookup for a given port. It does not know what is really listening on the other side. If you do a Google search for "list of known tcp ports", you will find long lists of standard port numbers. But they are only valid if the actual service is actually listening on that port. For the most part Macs do not listen on many ports, so your reuse of a port number that you are never going to use for its intended purpose is not important.

    HOWEVER, you can always try a different high numbered port. For example: 2211, 22101, 22102, 22103, etc..., assuming you wanted to keep a 22 in the number. Or just pick a value greater than 1024, and less than 65535.

    Message was edited by: BobHarris