External connection from SSH

2

I installed on my Ubuntu 16.04 the openssh-server and wanted to access my pc remotely through the terminal of other networks, such as the university, for example, but I'm only able to access through ssh when on the same network.

If someone can help me establish this external connection so I can access my pc while on another connection I would be very grateful.

I do not use a router, other than the one provided by Vivo (Router / mode Vivo Fibra).

NOTE: I do not intend to use putty, Team Viewer or anything, I just want to use the terminal, for me it's more practical.

I do not have fluence on English, sorry for this. Text translated by google.

Gustavo Luiz Bispo dos Santos

Posted 2018-09-04T20:27:22.317

Reputation: 23

This is the page of port forwarding on the router [https://i.imgur.com/yiX9hKt.png], but I dont know where I need to put the IP of my machine/router and the protocol that I need to use – Gustavo Luiz Bispo dos Santos – 2018-09-04T21:11:52.490

Welcome to Superuser! Instead of doing it as a comment, it is usually better to edit your question when adding information

– cybernetic.nomad – 2018-09-04T22:56:49.297

Answers

0

You have to find the external ip address, you can do that with https://www.whatismyip.com/ ....

You have to setup your ssh server, mainly your port.... set your port in /etc/ssh/sshd_config to something other than 22......then do

service ssh restart....

You have to have a username to use in the ssh command that you have permission to log into.....

You have to allow ssh in your iptables......like this:

iptables -I INPUT 1 -p tcp --dport PORT -j ACCEPT.....

-----------------------------------------------------------------------------

EDIT:

Do this↓↓↓↓↓↓↓↓↓ to add new port for ssh remember PORT in the command should be the port that you choose as maybe 34503

root@ubuntu:/# iptables -A INPUT -p tcp --dport PORT --jump ACCEPT
root@ubuntu:/# iptables-save

end of edit

-----------------------------------------------------------------------------

You have to be sure there is open through your router..... portforwarding the service ssh for the port you've chosen.....

You can also set ssh keys like here......https://www.debian.org/devel/passwordlessssh.......

then there is the command itself:

ssh -p PORT USER@EXTERNAL-IP

when you connect answer yes to the question if you trust the new connection..... and your all set, good luck

somethingSomething

Posted 2018-09-04T20:27:22.317

Reputation: 229

How can I allow this iptables -I INPUT 1 -p tcp --dport PORT -j ACCEPT – Gustavo Luiz Bispo dos Santos – 2018-09-04T22:16:12.527

why make things harder throuh changing port? makes things little bit more complicated and wont add any security – Sampo Sarrala - codidact.org – 2018-09-04T22:20:34.723

@Gustavo if you can access ssh from another PC in same network it means that you do not need to use iptables. However, if you already changed port and restarted sshd then it is possible that new port is closed. I'd say do not change ssh port. – Sampo Sarrala - codidact.org – 2018-09-04T22:26:42.270

I can access from other PC on the same network, but I need to access outside this network – Gustavo Luiz Bispo dos Santos – 2018-09-04T22:28:16.213

@GustavoLuizBispodosSantos I've updated my answer good luck – somethingSomething – 2018-09-04T22:32:10.837

@GustavoLuizBispodosSantos there are alot of how to's on portforwarding on the web, use google, search for your router and ssh portforwarding – somethingSomething – 2018-09-04T22:34:50.797

Solved with this link https://askubuntu.com/questions/1072129/external-connection-from-ssh#1072141

– Gustavo Luiz Bispo dos Santos – 2018-09-04T23:12:00.223

@GustavoLuizBispodosSantos cool that's great to hear, thanks for accepting – somethingSomething – 2018-09-04T23:13:43.680

@GustavoLuizBispodosSantos please upvote my answer – somethingSomething – 2018-09-04T23:14:41.007

1

If you want to access a public IP address then you need to know the public IP address, which is dynamic. If your PC is on the same domain as your Ubuntu server, then you can use the domain name instead of the IP address. Ex:

ssh user@subdomain.domainname.org

Frogmonkey

Posted 2018-09-04T20:27:22.317

Reputation: 76