my attempts to remote ssh to my Lubuntu SSH server time out. I have tried enabling port forwarding on my wifi router. As part of troubleshooting (and for security) i changed the sshd_config file # port entry from 22 to 1022. The LAN connection always works (same wifi router).

The amazing this is the LAN connection still works even though the SSH client is still using port 22. I am surprised at this since the SSHD_Config file is now port 1022.

Any idea of this and also how to troubleshoot the remote connection problem?

Thank you

edited question to include sshd_config per Robert Reidl's comment

#   $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $

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

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

# 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 1022
#AddressFamily any
#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 prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#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

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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 yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

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

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

Additional info:

port fwd config in 
router: ext: 1022 / 1022 
int: 1022 / 1022 22 
udp/tcp:    Both enabled:   Yes

UFW config 

To                         Action      From
--                         ------      ----
1022                       ALLOW IN    Anywhere
22/tcp                     ALLOW IN    Anywhere
1022 (v6)                  ALLOW IN    Anywhere (v6)
22/tcp (v6)                ALLOW IN    Anywhere (v6)
  • 3
    Restart ssh server – Panther Jan 22 '18 at 2:57
  • 1
    sudo /etc/init.d/ssh restart – Robert Riedl Jan 22 '18 at 6:23
  • @RobertRiedl i rebooted the laptop. Still able to use port 22. But the larger problem is why the SSH client cant connect from the external IP. I tried getting the IP from what's my IP and configuring it in the external field in port forwarding. Still doesnt work. – or Else Jan 23 '18 at 1:57
  • Can you post your complete sshd_config please ? – Robert Riedl Jan 23 '18 at 5:53
  • I posted it to the original question above. Thank you. – or Else Jan 23 '18 at 15:50

Remove the # infront of Port 1022 and in front of any other lines you wish to change then restart sshd.

That comments each line out, meaning your changes are not used and the defaults are.

  • thank you that was an obvious blunder. I removed the # and saved the file and restarted SSH. Still times out. Here is the fwdingin in the router ext: 1022 / 1022 int: 1022 / 1022 22 udp/tcp: Both enabled: Yes – or Else Jan 23 '18 at 18:38

Also when opening ports through your firewall/router, you can make the destination port as 22. So Source port 1022 destination port 22. That way on your local network you can do things under the default port 22, not having to change settings and such. However when connecting from the wan you would use port 1022 and your router will translate that to port 22 to your ip address of the machine on the network. In your example router ext: 1022 / 1022 int: 22 / 22 udp/tcp: Both enabled: Yes

just make sure you change it back to 22 on /etc/ssh/sshd_config

  • I think you need to uncomment #ListenAddress – JesseMP Jan 23 '18 at 19:09
  • The default values that work without any config are commented out in the default config. Uncommenting them does not change anything. You should uncomment only if you change the value to something other than what was already there. – user68186 Jan 23 '18 at 19:16
  • i changed to 1022 as a security measure but if router config int dest= 1022 AND sshd_config are both 1022 this should work, no? I don't know what other parameter needs to change and where. – or Else Jan 23 '18 at 19:54
  • can you connect locally via port 1022? – JesseMP Jan 23 '18 at 20:07
  • yes i can connect locally with port 1022. – or Else Jan 24 '18 at 0:35

Ha HA after turning off UFW and turning off the Router Firewall i was able to ssh from a remote location. Turning the Router Firewall to "low" i can still ssh from a remote location. The medium and high settings for firewall block ssh remote forwarding apparently. very interesting. fwiw the router is an ARRIS SBG6782-AC. Thanks everyone

Not the answer you're looking for? Browse other questions tagged or ask your own question.