You are not logged in.

#1 2021-02-18 14:43:38

opadfnezig
Member
Registered: 2021-02-18
Posts: 10

Can't ssh to machine from WAN

I've configured ssh and can ascess to it from lan, but can't do the same thing from wan. I have my port opened, and theoretically it should work well.

Also I can ascess my server from lan using adress 192.168.1.2:22 and it works well. I've checked if 60000 port is opened and sites says me yes. So, seems like the problem is in my local machine.
(router setup screen: https://ibb.co/59Mhky8)
Here is sshd config:

#	$OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

AllowUsers root

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	/usr/lib/ssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server

The question is: what am I doing wrong?

Last edited by opadfnezig (2021-02-18 16:24:58)

Offline

#2 2021-02-18 14:57:11

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,104

Re: Can't ssh to machine from WAN

PasswordAuthentication yes
…
AllowUsers root

STOP ALL EFFORTS and secure your ssh server first.
Read up https://wiki.archlinux.org/index.php/Security#SSH and sublinks.

Remove the oversized image and come back when done.

Offline

#3 2021-02-18 15:01:58

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,727

Re: Can't ssh to machine from WAN

And when you do come back, tell us what you're actually seeing.

Online

#4 2021-02-18 15:14:37

str0gg
Member
Registered: 2012-12-01
Posts: 75
Website

Re: Can't ssh to machine from WAN

is iptables up?

Offline

#5 2021-02-18 15:43:57

opadfnezig
Member
Registered: 2021-02-18
Posts: 10

Re: Can't ssh to machine from WAN

Remove the oversized image and come back when done.

Removed root from allow users, also set PermitRootLogin to no. You also quoted PasswordAuthentication yes, should I also disable it?
Also removed image).

I thought I will care about security when everything would work, as it's just home server, but ok.

Offline

#6 2021-02-18 15:46:13

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,104

Re: Can't ssh to machine from WAN

You also quoted PasswordAuthentication yes, should I also disable it?

Yes.

as it's just home server

When you open it to the WAN, it's everyones server…
Really read up the link.

Coming back to Scimmia: what does actually happen when you try to connect to it?

Offline

#7 2021-02-18 15:51:51

opadfnezig
Member
Registered: 2021-02-18
Posts: 10

Re: Can't ssh to machine from WAN

seth wrote:

You also quoted PasswordAuthentication yes, should I also disable it?

Yes.

as it's just home server

When you open it to the WAN, it's everyones server…
Really read up the link.

Coming back to Scimmia: what does actually happen when you try to connect to it?

Yes, somehow I forgot to say the main thing. I'm using putty to connect and it says me Network error: connection refused.
BTW just noticed that I forgot to allow my new user to sudo, so, I need some time to access the server manually XD.

Last edited by opadfnezig (2021-02-18 15:54:37)

Offline

#8 2021-02-18 15:58:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,104

Re: Can't ssh to machine from WAN

Can you try to access the server w/ openssh (windows 10 does actually provide that)?
Also ideally run

nmap -sV <wan_ip>

Offline

#9 2021-02-18 15:58:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,643

Re: Can't ssh to machine from WAN

I just checked.  There were 298 attempts to log in to my "home server" yesterday alone.   2254 since I booted on the 15th.  My router blocks all connections from several counties known for bad behavior before they can even reach my computer.  This results in the numbers I posted being mostly Europe and the US with the vast majority from other geolocations being blocked before reaching my system.

In other words, set sshd up to require either public keys, multifactor authentication, or both.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#10 2021-02-18 16:11:49

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Can't ssh to machine from WAN

Where does port 60000 come into this?

Are you actually attempting to connect from outside your network or are you just trying to use the external IP from inside your LAN?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#11 2021-02-18 16:13:30

Maniaxx
Member
Registered: 2014-05-14
Posts: 761

Re: Can't ssh to machine from WAN

- You cannot connect to yourself externally from/to the same IP. Some routers do NAT loopback but it can be very error prone.
- The connection gets refused that means it gets rejected not dropped. Someone picks up the packet (maybe bad port forward). Try tcpdump/wireshark on your server to see if the packets arrive at all. Even better check traffic on your router if possible.

Last edited by Maniaxx (2021-02-18 16:18:25)


sys2064

Offline

#12 2021-02-18 16:14:34

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,104

Re: Can't ssh to machine from WAN

He had a screenshot from his router, showing port 60000 being mapped to 22 on one of the local IPs.
(Sorry, I should have told him to to replace the image w/ a link… rather than to remove it)

Offline

#13 2021-02-18 16:25:25

twelveeighty
Member
Registered: 2011-09-04
Posts: 1,452

Re: Can't ssh to machine from WAN

ewaller wrote:

...My router blocks all connections from several counties

Not to get this topic off-topic, but is that built into your router itself? I've been trying to find a decent app/service that provides or calculates nftables-compatible IP blocking ranges based on geography but they either produce massive lists, are outdated or too restrictive or they charge too much. If my router could do it by itself, that's a much better solution.

Last edited by twelveeighty (2021-02-18 16:27:20)

Offline

#14 2021-02-18 16:27:26

opadfnezig
Member
Registered: 2021-02-18
Posts: 10

Re: Can't ssh to machine from WAN

Slithery wrote:

Where does port 60000 come into this?

Are you actually attempting to connect from outside your network or are you just trying to use the external IP from inside your LAN?

Yes, from inside. Didn't know this might be a problem. I'll try to do it from external network, just give me 10 mins to put the server back(I loosed ssh control, so only physical acces left).

Offline

#15 2021-02-18 16:52:07

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Can't ssh to machine from WAN

opadfnezig wrote:

Yes, from inside. Didn't know this might be a problem.

It's a problem if your router doesn't support NAT loopback. The vast majority of consumer routers don't have support.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#16 2021-02-18 16:54:50

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,643

Re: Can't ssh to machine from WAN

twelveeighty wrote:

Not to get this topic off-topic, but is that built into your router itself? I've been trying to find a decent app/service that provides or calculates nftables-compatible IP blocking ranges based on geography but they either produce massive lists, are outdated or too restrictive or they charge too much. If my router could do it by itself, that's a much better solution.

Yes.  It is an Asus router running Merlin Software with the Skynet plugin.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#17 2021-02-18 17:37:26

opadfnezig
Member
Registered: 2021-02-18
Posts: 10

Re: Can't ssh to machine from WAN

So, the problem was that I've tried to connect from my own network. I used mobile Internet to connect and it worked.
Thank you very much for the answers, I'm not a big fan of forums, but you are just great(best community I've ever seen).
Also thanks for preventing me from using password auth. I'll read about how to protect my network, and if I have any problems,I will let you know.

Offline

#18 2021-02-18 17:38:15

Maniaxx
Member
Registered: 2014-05-14
Posts: 761

Re: Can't ssh to machine from WAN

banIP (OpenWrt)
https://forum.openwrt.org/t/banip-support-thread/16985

Indeed not the worst idea to use something like this for publicly accessible services like SSHd.


sys2064

Offline

Board footer

Powered by FluxBB