If you want to connect to either computer, you will need to expose the computer through your router's NAT. Set up port forwarding to port 22 on both systems. Ideally, you will want to use keypair authentication and disable password access in /etc/ssh/sshd_config
.
Alternatively, if you have SSH access to a third system that can be exposed to the Internet, you can use SSH's built-in forwarding feature (man ssh
, look up the -R
and -L
options and optionally -n
) to open a port remotely that forwards back to your system. (For example: Computer A connects to the server with -R 2222:127.0.0.1:22
, and computer B connects to the server on port 2222 to gain access to computer A.) There is some overhead involved, however minor.
As a variation on the above port forwarding: You'll likely only be able to open ports on your home computer - this will probably be enough. But if you need to be able to access your work computer from home, you will need to set up your work computer to connect to your home computer with an -R
option as above. Then, you will be able to connect (ssh user@localhost:2222
) without difficulty.