Can not connect to SSH server on linux

Can not connect to SSH server on linux

I am running xubuntu 16.04. I am trying to connect to my machine through SSH, from the www.

I have tested ssh successfully through lan, so I know the ssh server is running correctly.

I then went into my router settings, went to Firewall->Allowed Applications, and forwarded a specific port to my linux machine. It asked me to choose a protocol, so selected TCP. After this failed I also tried UDP.

I then tried connected using my android phone on JuiceSSh. I entered in the public IP addr displayed by whatsmyip.com which was corroborated by my routers displayed public IP. I then disconnected my phone from lan. I confirmed my phone does have internet connection.

So anyways, at this point the connection failed, and I am not sure why, or what my next step should be in diagnosing this.

If I changed from my custom port, to just port 22, the connection succeeded. Could this be an issue on my linux servers ssh configuration?

答案1

To make sure your ISP, or modem in front of your router are not responsible, try connecting to your machine using routers IP. So, after you've set up port forwarding:

ssh [email protected] -p 2222

If you are using a password to connect (which is common when using JuiceSSH), make sure that your /etc/ssh/sshd_config allows password authentication from your phone's public IP address: PasswordAuthentication yes.

If you are trying to connect as root, you need to allow external root login: PermitRootLogin yes

Don't forget to restart your ssh server after each important change in settings:

sudo service ssh restart

答案2

The problem was that although I was forwarding port 2222 to my linux server, I did up update the /etc/ssh/sshd_config file to listen on port 2222. Once I updated the config to listen on the correct port, I was able to connect correctly.

相关内容