Cannot SSH into server on same network

Hi there!

I’ve followed the instructions listed here: Arch Linux SSH Server Setup, Customization and Optimization. After changing the port on the server (via sshd_config), my ssh on my client hangs when I try to connect. Interestingly enough, local connections worked a until I changed my sshd_config.

Anyways, I found the following sshd_config to try and reset mine

#    $OpenBSD: sshd_config,v 1.89 2013/02/06 00:20:42 dtucker 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 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires explicit activation of protocol 1
#Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

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

#RSAAuthentication yes
#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
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and 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 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
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox        # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#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
#    ForceCommand cvs server

and restarted my sshd via sudo systemctl restart sshd. Running sudo systemctl status sshd got me

● sshd.service - OpenSSH Daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: disabled)
     Active: active (running) since Tue 2022-09-27 23:16:19 PDT; 18s ago
   Main PID: 477 (sshd)
      Tasks: 1 (limit: 38335)
     Memory: 2.4M
        CPU: 6ms
     CGroup: /system.slice/sshd.service
             └─477 "sshd: /usr/bin/sshd -D [listener] 0 of 10-100 startups"

Sep 27 23:16:19 iq-desktop systemd[1]: Started OpenSSH Daemon.
Sep 27 23:16:19 iq-desktop sshd[477]: Server listening on 0.0.0.0 port 22.
Sep 27 23:16:19 iq-desktop sshd[477]: Server listening on :: port 22.

So I tried to connect again, but it now hangs infinitely too. The same persists even after I reboot my machine(s). When I run sudo netstat -tulpn | grep LISTEN I get

tcp    0   0 127.0.0.1:17603        0.0.0.0:*       LISTEN      2570/dropbox        
tcp    0   0 127.0.0.1:17600        0.0.0.0:*       LISTEN      2570/dropbox        
tcp    0   0 0.0.0.0:22             0.0.0.0:*       LISTEN      70903/sshd: /usr/bi
tcp    0   0 0.0.0.0:17500          0.0.0.0:*       LISTEN      2570/dropbox        
tcp6  0   0 :::22                   :::*            LISTEN      70903/sshd: /usr/bi
tcp6  0   0 :::17500                :::*            LISTEN      2570/dropbox        

which seems to tell me that the port SHOULD be open and listened to?

Just to check, the firewall is open on port 22 or disabled/removed?

When I run netstat -tuplen I get the following:

Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
tcp        0      0 0.0.0.0:17500           0.0.0.0:*               LISTEN      1000       28874      2515/dropbox        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          55599      -                   
tcp        0      0 127.0.0.1:17600         0.0.0.0:*               LISTEN      1000       27359      2515/dropbox        
tcp        0      0 127.0.0.1:17603         0.0.0.0:*               LISTEN      1000       27362      2515/dropbox        
tcp6       0      0 :::17500                :::*                    LISTEN      1000       28873      2515/dropbox        
tcp6       0      0 :::22                   :::*                    LISTEN      0          55601      -                   
udp        0      0 0.0.0.0:17500           0.0.0.0:*                           1000       28875      2515/dropbox        
udp        0      0 0.0.0.0:36333           0.0.0.0:*                           0          19149      -                   
udp        0      0 0.0.0.0:37549           0.0.0.0:*                           974        14875      -                   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           974        14873      -                   
udp6       0      0 fe80::7e5:15a4:4a67:546 :::*                                0          21248      -                   
udp6       0      0 :::36333                :::*                                0          19150      -                   
udp6       0      0 :::53630                :::*                                974        14876      -                   
udp6       0      0 :::5353                 :::*                                974        14874      -                   

which seems to show that it is listening? I stumbled on this solution when I googled.

When running sudo iptables -L -n I get

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Here is a Endeavouros WiKi article on setting up a Linux client
https://discovery.endeavouros.com/arm/homeserver-set-up-a-linux-client-computer/2021/03/

Maybe something in this will help?

Does the SERVER have a static IP address?

Pudge

Here is a Endeavouros WiKi article on setting up a Linux client
https://discovery.endeavouros.com/arm/homeserver-set-up-a-linux-client-computer/2021/03/

I THINK that I followed the instructions for setting it up, at least up to the section on " Connect to enosServer with SSH" but when I tried to ssh in it led to an error.

I’m not sure what’s happening as it worked initially…Would you mind sharing your sshd_config assuming it is the default? Maybe there’s something up with the one I found online

Here is the default file:

#       $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker 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 prohibit-password
#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

# Change to no to disable s/key passwords
KbdInteractiveAuthentication 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 KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication 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 KbdInteractiveAuthentication 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

Could you list the error exactly.

Pudge

usually there is no need to change default config/s for normal password username login over ssh.
You only need to enable sshd on the server and open the/disable the firewall on the server.
But depending on your local network setup the used Router could also block ssh.

This is a common pitfall - default the root login is disabled using password - therefore it is important to have a non-priviliged user for ssh access.

Your issue may be that simple.

On the other hand - on your local network you don’t need to change ssh port - unless paranoid of course - but if the firewalld service is enabled and active you need to allow ssh traffic

On the server part

  • if seems from your initial topic you did change port?
    • did you restart the service?
  • Is firewalld enabled?
    systemctl status firewalld
    

On the server - if firewalld status is enabled and running - and the port is default 22 - execute

sudo firewall-cmd --zone=public --add-service=ssh --permanent

If you have changed the port you need to add a custom rule to firewalld which enables that port.

Copy the default ssh rule and give it a name e.g. my-ssh

sudo cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/my-ssh.xml

Then use an editor to edit the rule file and change the port number and name - and e.g. your chosen port number is 30000 it would be

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>My SSH service</short>
  <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description>
  <port protocol="tcp" port="30000"/>
</service>

Then enable the custom service definition

sudo firewall-cmd --zone=public --add-service=my-ssh --permanent

Then you would connect to the server using the custom port

ssh user@ip.x.y.z -p 30000
1 Like

Sorry, the error is that it just seems stuck and after some time reports that

ssh: connect to host 10.0.0.60 port 22: Operation timed out

That is where 10.0.0.60 was obtained from running ip a on my server, and port 22 was the default port after taking the default from the kind dalto.

I’m testing on local network before going to exposing my port to the scary world. I figure if it can’t connect locally (on another computer) because of some issue I don’t understand, that it’s definitely not going to work when I scale it up. Hence my wanting to change the port as per most guides I’ve read online

Can you run ssh in verbose mode and post the output here?

ssh -v

common pitfall

Yeah, I did that intentionally. I didn’t want the user to be able to log in as root. Is that bad? At least initially, with the default configs, I was able to SSH in no issues.


if seems from your initial topic you did change port?

Yeap! I changed from 22 to 60268 and then back to 22.

did you restart the service

I did using

sudo systemctl restart sshd and I checked the status using sudo systemctl status sshd and the log spit out didn’t seem to indicate any errors.

Is firewalld enabled?

Yeap! In response to your statement about firewalls, I used sudo ufw allow 22 and sudo ufw allow 60268 for good measure. Is that enough?

I we don’t use ufw on :enos: .
We use firewalld

I’m mostly following Endeavour OS Discovery: Homeserver 1 – Set up a Linux client computer from Pudge


Anyways, I think that doing a sudo ufw reset solved my issue so I’m closing this. Thank you everyone for all your time and help!

1 Like

Nice to hear.

@Pudge should the Homeserver post be updated with firewalld instead of ufw?

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.