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.
To install SSH on Linux using terminal
To see if ssh is installed on Linux (the client) to see if it is installed on the computer type:
ssh
To see if ssh server is installed on the Linux system type:
ssh local host
local host (is the loopback IP address, the IP address that the computer uses to talk to the same Linux OS)
To install ssh server type:
sudo apt-get install openssh-server
To see if the ssh server is active type this:
sudo service ssh status
type Ctrl+c after this if the terminal won't let you type anything now.
If the server is active you can type this command to start it:
sudo service ssh start
Then you can use this command to to see if it is now active:
sudo service ssh status
Type Ctrl+c after this if the terminal won't let you type anything now.
and to stop the SSH server you can type this if want to stop it sometime:
sudo service ssh stop
you can also check the status using this command to make sure it stopped:
sudo service ssh status
If you are using Virtual Box and need to type Ctrl+c, make sure you hold down the Ctrl button and then type c while still holding Ctrl; Virtual Box uses this key as default as the host key so you might have to try the other Ctrl button on the keyboard if this is not working.
Best Answer
We will need more information, for example, the content of sshd_config (eg., /etc/ssh/sshd_config) file, and the state of the server IP tables ("iptables -L" ran as root or through sudo).
A couple of things that worked for me in the past:
Do you have a router between your computer and the server? Is it blocking port 22? Is your ISP blocking port 22?
Try another port by changing the Port directive in your sshd config file and restarting your sshd daemon:
Port 2222
Are you using TCP wrappers (e.g., what do you see in /etc/hosts.allow)? This is independent of the firewall.
As a previous user mentioned, are you trying to log as root (not recommended, but then, you need "PermitRootLogin yes")?