How can I set up SSH on home network from Windows 7 to Linux

ssh

I have a windows 7 machine and a linux machine. I want to SSH from windows to linux. How would I set this up if both are connected to my router at home? Would there be any changes necessary if I left my linux machine at home but took my windows machine with me to starbucks?

So far I've installed putty and disabled the firewall on both machines.

Ubuntu: sudo ufw disable

Windows: Simply disabled Windows firewall

Putty: Typed in the IP of my Ubuntu machine (both local and external IPs)

After I click connect, I get a connection refused message.

Best Answer

First of all, both machines should be on the same subnet (e.g., 192.168.1.x). As an initial test, try pinging the Linux machine from Windows (ping -t <Linux IP>) and you should get a response. If you don't get a response, you won't be able to use SSH, and need to reconfigure your network.

Secondly, you need to install an SSH server on your Linux machine. Since you're using Ubuntu, follow this guide on how to install OpenSSH.

The SSH server will be set to be run in the background, and I recommend you turning the Linux firewall back on and opening the ports it's listening on (usually TCP port 22). You can do that with:

sudo ufw allow ssh

Once that is setup, and you can ping your Linux machine from Windows, you should be able to use Putty or any other Windows SSH client to connect to your Linux machine. Just input your Linux IP and port and you should be good to go.

Now, if you want to connect from outside your home network, you will probably need to configure port forwarding for your router. This greatly depends from manufacturer to manufacturer, but it basically involves mapping your WAN IP to your LAN IP for the SSH port. Google for <router name and model> port forwarding and you should get some results.

Port forwarding is only half of the equation, though. Your home Internet connection probably doesn't have a static public IP, which changes anytime you power cycle your router or your ISP forces an IP change. To get around having to remember your new public IP address everytime it changes, you can setup a dynamic DNS service. Which means you can enter a domain name (e.g. ssh.myhost.com) instead of an IP.

There are many free dynamic DNS services, such as No-IP, FreeDNS, etc. You usually have to run their client on your Linux machine which will update their DNS records anytime your public IP changes. Most routers though have this feature built-in, so check your router's admin page.

Related Question