Today's Deals (in Amazon.com)

 Question:

Raspberry Pi Remote SSH Connection
  • LordSputnik

    So, I've been using SSH from an Ubuntu desktop to access my Raspberry Pi over the LAN using the command:

    ssh 192.168.1.185
    

    or occasionally

    ssh -YC 192.168.1.185
    

    I'll be moving in a few days, and the Pi isn't going with me, so I need to be able to access the Pi from a remote network, over the internet. I've tried forwarding port 22 on my router, but when trying:

    ssh <external ip>
    

    I get:

    ssh: connect to host <external ip> port 22: Connection refused
    

    I don't know what information might be helpful to provide, but looking around some similar questions "netstat -tlpn" is usually useful:

    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2733/lighttpd   
    tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      15009/pure-ftpd (SE
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      20234/sshd      
    tcp        0      0 0.0.0.0:19048           0.0.0.0:*               LISTEN      3433/python     
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      2993/mysqld
    

    My ssh_config may also be useful, so here is that, in full:

    # Package generated configuration file
    # See the sshd_config(5) manpage for details
    
    # What ports, IPs and protocols we listen for
    Port 22
    # Use these options to restrict which interfaces/protocols sshd will bind to
    ListenAddress ::
    ListenAddress 0.0.0.0
    Protocol 2
    # 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
    #Privilege Separation is turned on for security
    UsePrivilegeSeparation yes
    
    # Lifetime and size of ephemeral version 1 server key
    KeyRegenerationInterval 3600
    ServerKeyBits 768
    
    # Logging
    SyslogFacility AUTH
    LogLevel INFO
    
    # Authentication:
    LoginGraceTime 120
    PermitRootLogin yes
    StrictModes yes
    
    RSAAuthentication yes
    PubkeyAuthentication yes
    #AuthorizedKeysFile     %h/.ssh/authorized_keys
    
    # Don't read the user's ~/.rhosts and ~/.shosts files
    IgnoreRhosts yes
    # For this to work you will also need host keys in /etc/ssh_known_hosts
    RhostsRSAAuthentication no
    # similar for protocol version 2
    HostbasedAuthentication no
    # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
    #IgnoreUserKnownHosts yes
    
    # To enable empty passwords, change to yes (NOT RECOMMENDED)
    PermitEmptyPasswords no
    
    # Change to yes to enable challenge-response passwords (beware issues with
    # some PAM modules and threads)
    ChallengeResponseAuthentication no
    
    # Change to no to disable tunnelled clear text passwords
    #PasswordAuthentication yes
    
    # Kerberos options
    #KerberosAuthentication no
    #KerberosGetAFSToken no
    #KerberosOrLocalPasswd yes
    #KerberosTicketCleanup yes
    
    # GSSAPI options
    #GSSAPIAuthentication no
    #GSSAPICleanupCredentials yes
    
    X11Forwarding yes
    X11DisplayOffset 10
    PrintMotd no
    PrintLastLog yes
    TCPKeepAlive yes
    #UseLogin no
    
    #MaxStartups 10:30:60
    #Banner /etc/issue.net
    
    # Allow client to pass locale environment variables
    AcceptEnv LANG LC_*
    
    Subsystem sftp /usr/lib/openssh/sftp-server
    
    # 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
    

    Many thanks to anyone who can help!

  •  Answers:

  • Ryanteck

    One thing to check is to make sure that you test connecting via SSH from another computer on a different internet connection. I found with some routers that they reject internal users from connecting via the external IP but allow you to actually connect via the external IP to SSH in.

    You can likely try this via a mobile phone (I know androids allow you to access SSH with an application).

    Hope this helps ;)