Connect SSH to server on port 2222 via the terminal
Matthew Martinez
I cannot SSH into my server via the terminal. So far I've tried:
ssh root@ip-address and ssh username@ip-address
but neither has worked. I'm getting a blank screen for a while and then eventually
operation timed out
I've also tried switching to a different location with a different Internet Service Provider, so I'm fairly sure that the problem isn't a firewall.
I can login via FTP.
This is what I get:
$ ssh hosting-account-username@ip-address
ssh: connect to host ip-address port 22: Operation timed outI've also tried this with no result:
$ nc ip-address 22I've pinged the address:
$ ping ip-address
64 bytes from ip-address icmp_seq=143 ttl=45 time=44.543 ms
64 bytes from ip-address icmp_seq=143 ttl=45 time=43.686 ms
64 bytes from ip-address icmp_seq=143 ttl=45 time=46.501 ms
-- and so on My hosting company has told me I do have SSH, but on port 2222 (instead of 22) because I have a shared hosting account and tried this:
$ nc ip-address -p [2222]
nc: missing hostname and port
usage: nc [-46AacCDdEFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] [-p source_port] [--apple-delegate-pid pid] [--apple-delegate-uuid uuid] [-s source_ip_address] [-w timeout] [-X proxy_version] [-x proxy_address[:port]] [hostname] [port[s]]
$ ssh username@ip-address:2222
ssh: Could not resolve hostname ip-address:2222: nodename nor servname provided, or not knownNot sure what else to try.
53 Answers
The -p option in nc command is for source port and you need to specify destination port.
Try $ nc ip-address 2222 to check if you can reach the port.
Also I don't think than ssh command accept the syntax hostname:port.
Try $ ssh -p 2222 username@ip-address instead.
It is rather common to run the ssh service on a non-default port to prevent brute force attacks, etc. so you need to specify the (correct!) port number. If you aren't sure what this is, you can check with your service provider or if you have some other method of accessing the service with sudo netstat -ltnp | grep ssh
To connect, assuming you are using port 2222
ssh -p 2222 user@hostWill work. For scp or sftp, the option changes to upper case so
scp -P 2222 user@host:/path/to/remote/file /path/to/local/destinationIf you are on a *nix system (Mac included) you can edit ~/.ssh/config and create profiles that handle the various port options, etc.
Host webhost HostName Port 2222 User webmaster IdentityFile ~/.ssh/www-private-keyAnd then simply connect via ssh webhost since the webhost profile specifies hostname, port number, user, etc. for the connection.
What worked for me was to use ssh user@IP -p 2222. Was asked for the password, got in right away.