Connecting to Ubuntu server via SSH externally
First of all, the correct command is:
ssh [email protected]
And the router should be configured to forward the SSH port 22 to your server's local IP address.
For further debugging:
1) Check that port 22 (SSH) is open on your server and on the router (port forwarding).
2) Check that the SSH server is running on your server
3) Use ping
, ssh -v
while connecting and look at /var/log/auth.log
to debug any further connection problems.
1) On your router: follow router specific instructions
On your server: sudo ufw status
(unless you use another firewall configuration utility) or sudo iptables -L
(general method, but complex output)
To open port 22: sudo ufw allow 22
cf https://help.ubuntu.com/12.04/serverguide/firewall.html
2) Check it is installed: dpkg -l openssh-server
Check it is running: service ssh status
or ps aux | grep sshd
3) On the connecting client:
ping my.external.ip.address
ssh -v [email protected]
On the server:
sudo less /var/log/auth.log
You can check the router logs as well if necessary.
Here's an online port scanner: https://www.grc.com/x/ne.dll?bh0bkyd2
I think you can use tools like nmap or other as well, but I'm not that familiar with them yet.
Dealing with a changing external IP address:
1) Get a dynDNS or similar account: http://dyn.com/dns/
Lists of dynamic DNS providers:
- http://dnslookup.me/dynamic-dns/
- http://www.dmoz.org/Computers/Internet/Protocols/DNS/DNS_Providers/Dynamic_DNS/
2) Another solution, is to set up a crontab job, which regularly mails you your external IP address or puts in into an online storage service like dropbox.
Here's a script a friend of mine uses:
#!/bin/bash
# Bash script to get the external IP address
MYWANIP=$(curl http://mire.ipadsl.net | sed -nr -e 's|^.*<span class="ip">([0-9.]+)</span>.*$|\1| p')
echo "My IP address is: $MYWANIP"
IPold=$(cat /home/USER/Dropbox/test.txt)
echo "Previous IP Address: $IPold"
if [[ $IPold != $MYWANIP ]] ;
then
echo "New IP"
rm /home/USER/Dropbox/test.txt
echo $MYWANIP >> /home/USER/Dropbox/test.txt;
echo $MYWANIP;
else
echo "Same IP";
fi
# example crontab entry:
## m h dom mon dow command
## */10 * * * * /home/USER/Dropbox/test_ip.sh
Router port forwarding:
1) First, figure out your router's local IP address by running:
ip route | grep default
It is usually something like 192.168.x.x.
Alternative ways and other OS solutions:
- https://www.cyberciti.biz/faq/how-to-find-gateway-ip-address/
- http://www.howtogeek.com/233952/how-to-find-your-routers-ip-address-on-any-computer-smartphone-or-tablet/
- https://wiki.amahi.org/index.php/Find_Your_Gateway_IP
- https://portforward.com/networking/routers_ip_address.htm
2) Using any computer connected locally to the router, access the IP found previously, i.e. via http://192.168.1.1 for example. This should bring up the router configuration interface.
3) The next steps vary depending on your router. Here is how it is done on a router with OpenWRT for example:
https://newspaint.wordpress.com/2012/08/26/how-to-add-a-port-forward-using-the-web-interface-on-openwrt-10-03-1/
By default in Ubuntu (Desktop) SSH is not installed.
You can install it by the following command in Terminal:
sudo apt-get install openssh-server
It should install and start the service right away.