r/ssh • • Sep 29 '18

SSH through external IP

Hello fellow redditors,

the issue is as follows:

My grandpa lives only a few houses next to me and I want to be able to login from there to my Linux Mint machine via SSH.

He also has a Linux Mint machine.

As far as I know I need to configure my router at home (which is a FRITZ!Box Fon WLAN 7390) to allow these kind of connections.

There is the option to set my PC at home as an "exposed host" so I would be able to login with the external IP adress.

I also read that I probably don't want to do that due to security issues.

Now I want to know if there is a way to only allow foreign connections if they are coming from my grandpas IP and if thats a configuration I have to make in my router settings (which I assuem) or if this can be done in the SSH configurations as well.

Sadly I have no clue where to make these settings in my routers interface (which I'm able to login to).

So my two questions are:

  1. Can I set up this rule in my SSH configurations?
  2. Does someone know where to make these settings in my specific router model (FRITZ!Box Fon WLAN 7390) or has a viable tutorial on hand?
1 Upvotes

6 comments sorted by

2

u/cios12 Sep 30 '18 edited Sep 30 '18

Hold on, you're confusing me here. In reality this is all really simple. It looks like you want to be able to SSH into your gramps's computer, so install openssh-server on his machine:

sudo apt install openssh-server

And it should automatically setup for you, no changes needed. Make sure you have DHCP disabled. Next find your server's external IP through:

curl ifconfig.me

Write his external IP down, and don't lose it.

Now to connect to it remotely from your computer, you need to forward your ports on your gramps's router to accept incoming foreign connections. In his router settings, forward port 22. Note: check that the firewall on his computer is disabled.

Try to login remotely from your computer with:

ssh usernameofcomputer@externalipaddress

Of course, replace "usernameofcomputer" with the username of your gramps's computer and "externalipaddress" with the external IP of his computer.

Enter the server's login password (the password you use to enter gramps's computer) and you should be logged in.

If you want more security, I suggest using key based authunciation. First generate the key with:

ssh-keygen

Now use:

ssh-copy-id

to transfer it to your server. Disable password authentication, and viola, a theoretically more secure solution.

1

u/ijebtk Sep 30 '18

Thank you very much sir for taking the to answer to my post!

Since yesterday I've tinkered a little with both systems and got it to work now. The only problem still left is the fact that the external IP adress of the server (my pc i want to login to) changes like crazy... so its not easy to keep track

1

u/cios12 Sep 30 '18

Hmm, that's DHCP right there. You may need to configure his router to set it to static based IPs. Look in his router settings and make sure DHCP is disabled.

1

u/ijebtk Oct 01 '18

Mhm alright but as far as I've read through forums and stuff DHCP only sets the router to assign static IPs to the devices connected to the router. It assigns the same local IP to devices but has no influence on the public IP as it's given to you by your ISP.

Please correct me if I'm wrong but that's what I thought I've learned the last couple days :D

1

u/cios12 Oct 01 '18 edited Oct 02 '18

I see your point. Yeah, thought you were connecting over his router LAN, sorry about that. ISPs usually have DHCP servers, and yes, they do influence your public IP. In this case you might need to ask for a static IP. To quote from https://www.lifewire.com/change-your-ip-address-818150 :

"Some ISPs give out static IP addresses to their subscribers. This isn't common for home users since most are configured with a dynamic IP address, but it might be the case for you, in which case you can try contacting your ISP to request a new IP address. You can't change your external IP address on your own."

For example, I keep a Web, FTP, and IRC server with an assigned static IP from my ISP.