I've setup my SSH server to use public key authentication. When I connect to my server on local network, it authenticates. But it doesn't when I connect over the internet.I don't think the problem is port forwarding. It used to work before disabling password login in the server.Here is the output of ssh -vvv user@example.comOpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011debug1: Reading configuration data /etc/ssh_configdebug1: /etc/ssh_config line 20: Applying options for *debug1: /etc/ssh_config line 53: Applying options for *debug2: ssh_connect: needpriv 0debug1: Connecting to example.com [1.2.3.4] port 22.debug1: Connection established.debug3: Incorrect RSA1 identifierdebug3: Could not load /Users/myuser/.ssh/id_rsa as a RSA1 public keydebug1: identity file /Users/myuser/.ssh/id_rsa type 1debug1: identity file /Users/myuser/.ssh/id_rsa-cert type -1debug1: identity file /Users/myuser/.ssh/id_dsa type -1debug1: identity file /Users/myuser/.ssh/id_dsa-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_6.2debug1: Remote protocol version 2.0, remote software version dropbear_0.52debug1: no match: dropbear_0.52debug2: fd 3 setting O_NONBLOCKdebug3: put_host_port: [example.com]:22debug3: load_hostkeys: loading entries for host [example.com]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:2debug3: load_hostkeys: loaded 1 keysdebug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsadebug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-dssdebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: diffie-hellman-group1-sha1debug2: kex_parse_kexinit: ssh-rsa,ssh-dssdebug2: kex_parse_kexinit: aes128-ctr,3des-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,twofish256-cbc,twofish-cbc,twofish128-cbc,blowfish-cbcdebug2: kex_parse_kexinit: aes128-ctr,3des-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,twofish256-cbc,twofish-cbc,twofish128-cbc,blowfish-cbcdebug2: kex_parse_kexinit: hmac-sha1-96,hmac-sha1,hmac-md5debug2: kex_parse_kexinit: hmac-sha1-96,hmac-sha1,hmac-md5debug2: kex_parse_kexinit: nonedebug2: kex_parse_kexinit: nonedebug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_setup: found hmac-md5debug1: kex: server->client aes128-ctr hmac-md5 nonedebug2: mac_setup: found hmac-md5debug1: kex: client->server aes128-ctr hmac-md5 nonedebug2: dh_gen_key: priv key bits set: 132/256debug2: bits set: 501/1024debug1: sending SSH2_MSG_KEXDH_INITdebug1: expecting SSH2_MSG_KEXDH_REPLYdebug1: Server host key: RSA 10:21:9f:80:7b:a3:94:0d:ca:3b:15:fd:e1:37:20:eedebug3: put_host_port: [1.2.3.4]:22debug3: put_host_port: [example.com]:22debug3: load_hostkeys: loading entries for host [example.com]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:2debug3: load_hostkeys: loaded 1 keysdebug3: load_hostkeys: loading entries for host [1.2.3.4]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:2debug3: load_hostkeys: loaded 1 keysdebug1: Host '[example.com]:22' is known and matches the RSA host key.debug1: Found key in /Users/myuser/.ssh/known_hosts:2debug2: bits set: 534/1024debug1: ssh_rsa_verify: signature correctdebug2: kex_derive_keysdebug2: set_newkeys: mode 1debug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug2: set_newkeys: mode 0debug1: SSH2_MSG_NEWKEYS receiveddebug1: Roaming not allowed by serverdebug1: SSH2_MSG_SERVICE_REQUEST sentdebug2: service_accept: ssh-userauthdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug2: key: /Users/myuser/.ssh/id_rsa (0x7fc0336004b0),debug2: key: /Users/myuser/.ssh/id_dsa (0x0),debug1: Authentications that can continue: publickey,passworddebug3: start over, passed a different list publickey,passworddebug3: preferred publickey,keyboard-interactive,passworddebug3: authmethod_lookup publickeydebug3: remaining preferred: keyboard-interactive,passworddebug3: authmethod_is_enabled publickeydebug1: Next authentication method: publickeydebug1: Offering RSA public key: /Users/myuser/.ssh/id_rsadebug3: send_pubkey_testdebug2: we sent a publickey packet, wait for replydebug1: Authentications that can continue: publickey,passworddebug1: Trying private key: /Users/myuser/.ssh/id_dsadebug3: no such identity: /Users/myuser/.ssh/id_dsa: No such file or directorydebug2: we did not send a packet, disable methoddebug3: authmethod_lookup passworddebug3: remaining preferred: ,passworddebug3: authmethod_is_enabled passworddebug1: Next authentication method: passworduser@example.com's password:and here my server's sshd_config:# Package generated configuration file# See the sshd_config(5) manpage for details# What ports, IPs and protocols we listen forPort 22# Use these options to restrict which interfaces/protocols sshd will bind to#ListenAddress ::#ListenAddress 0.0.0.0Protocol 2# HostKeys for protocol version 2HostKey /etc/ssh/ssh_host_rsa_keyHostKey /etc/ssh/ssh_host_dsa_keyHostKey /etc/ssh/ssh_host_ecdsa_key#Privilege Separation is turned on for securityUsePrivilegeSeparation yes# Lifetime and size of ephemeral version 1 server keyKeyRegenerationInterval 3600ServerKeyBits 768# LoggingSyslogFacility AUTHLogLevel INFO# Authentication:LoginGraceTime 120PermitRootLogin noStrictModes yesRSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile  %h/.ssh/authorized_keys# Don't read the user's ~/.rhosts and ~/.shosts filesIgnoreRhosts yes# For this to work you will also need host keys in /etc/ssh_known_hostsRhostsRSAAuthentication no# similar for protocol version 2HostbasedAuthentication 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 passwordsPasswordAuthentication no# Kerberos options#KerberosAuthentication no#KerberosGetAFSToken no#KerberosOrLocalPasswd yes#KerberosTicketCleanup yes# GSSAPI options#GSSAPIAuthentication no#GSSAPICleanupCredentials yesX11Forwarding yesX11DisplayOffset 10PrintMotd noPrintLastLog yesTCPKeepAlive yes#UseLogin no#MaxStartups 10:30:60#Banner /etc/issue.net# Allow client to pass locale environment variablesAcceptEnv 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 yesIf it's at all useful, my server is Raspbian and my client is OS X MavericksEDIT: the permission of the ~/.ssh directory in the server is set to 700. The authorized_keys file is set to 600.EDIT: Log of internal connection:$ ssh 192.168.2.145 -l user -vvv                                                                                                          [14:48:01]OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011debug1: Reading configuration data /etc/ssh_configdebug1: /etc/ssh_config line 20: Applying options for *debug1: /etc/ssh_config line 53: Applying options for *debug2: ssh_connect: needpriv 0debug1: Connecting to 192.168.2.145 [192.168.2.145] port 22.debug1: Connection established.debug3: Incorrect RSA1 identifierdebug3: Could not load /Users/myuser/.ssh/id_rsa as a RSA1 public keydebug1: identity file /Users/myuser/.ssh/id_rsa type 1debug1: identity file /Users/myuser/.ssh/id_rsa-cert type -1debug1: identity file /Users/myuser/.ssh/id_dsa type -1debug1: identity file /Users/myuser/.ssh/id_dsa-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_6.2debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*debug2: fd 3 setting O_NONBLOCKdebug3: put_host_port: [192.168.2.145]:22debug3: load_hostkeys: loading entries for host [192.168.2.145]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:1debug3: load_hostkeys: loaded 1 keysdebug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsadebug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-dssdebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: none,zlib@openssh.comdebug2: kex_parse_kexinit: none,zlib@openssh.comdebug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_setup: found hmac-md5debug1: kex: server->client aes128-ctr hmac-md5 nonedebug2: mac_setup: found hmac-md5debug1: kex: client->server aes128-ctr hmac-md5 nonedebug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_GROUPdebug2: dh_gen_key: priv key bits set: 128/256debug2: bits set: 514/1024debug1: SSH2_MSG_KEX_DH_GEX_INIT sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_REPLYdebug1: Server host key: RSA 12:1b:b5:5b:ab:f9:55:ed:e9:e9:56:cf:8c:a1:4c:4edebug3: put_host_port: [192.168.2.145]:22debug3: put_host_port: [192.168.2.145]:22debug3: load_hostkeys: loading entries for host [192.168.2.145]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:1debug3: load_hostkeys: loaded 1 keysdebug3: load_hostkeys: loading entries for host [192.168.2.145]:22 from file /Users/myuser/.ssh/known_hostsdebug3: load_hostkeys: found key type RSA in file /Users/myuser/.ssh/known_hosts:1debug3: load_hostkeys: loaded 1 keysdebug1: Host '[192.168.2.145]:22' is known and matches the RSA host key.debug1: Found key in /Users/myuser/.ssh/known_hosts:1debug2: bits set: 534/1024debug1: ssh_rsa_verify: signature correctdebug2: kex_derive_keysdebug2: set_newkeys: mode 1debug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug2: set_newkeys: mode 0debug1: SSH2_MSG_NEWKEYS receiveddebug1: Roaming not allowed by serverdebug1: SSH2_MSG_SERVICE_REQUEST sentdebug2: service_accept: ssh-userauthdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug2: key: /Users/myuser/.ssh/id_rsa (0x7ffeda40b940),debug2: key: /Users/myuser/.ssh/id_dsa (0x0),debug1: Authentications that can continue: publickeydebug3: start over, passed a different list publickeydebug3: preferred publickey,keyboard-interactive,passworddebug3: authmethod_lookup publickeydebug3: remaining preferred: keyboard-interactive,passworddebug3: authmethod_is_enabled publickeydebug1: Next authentication method: publickeydebug1: Offering RSA public key: /Users/myuser/.ssh/id_rsadebug3: send_pubkey_testdebug2: we sent a publickey packet, wait for replydebug1: Server accepts key: pkalg ssh-rsa blen 279debug2: input_userauth_pk_ok: fp 8e:81:e9:af:21:99:69:37:61:69:3a:76:b9:42:00:00debug3: sign_and_send_pubkey: RSA 8e:81:e9:af:21:99:69:37:61:69:3a:76:b9:42:00:00debug1: read PEM private key done: type RSAdebug1: Authentication succeeded (publickey).Authenticated to 192.168.2.145 ([192.168.2.145]:22).debug1: channel 0: new [client-session]debug3: ssh_session2_open: channel_new: 0debug2: channel 0: send opendebug1: Requesting no-more-sessions@openssh.comdebug1: Entering interactive session.debug2: callback startdebug2: fd 3 setting TCP_NODELAYdebug3: packet_set_tos: set IP_TOS 0x10debug2: client_session2_setup: id 0debug2: channel 0: request pty-req confirm 1debug1: Sending environment.debug3: Ignored env PATHdebug3: Ignored env TMPDIRdebug3: Ignored env SHELLdebug3: Ignored env HOMEdebug3: Ignored env USERdebug3: Ignored env LOGNAMEdebug3: Ignored env SSH_AUTH_SOCKdebug3: Ignored env Apple_PubSub_Socket_Renderdebug3: Ignored env DISPLAYdebug3: Ignored env __CHECKFIX1436934debug3: Ignored env __CF_USER_TEXT_ENCODINGdebug3: Ignored env SECURITYSESSIONIDdebug3: Ignored env TERM_PROGRAMdebug3: Ignored env PWDdebug1: Sending env LC_CTYPE = debug2: channel 0: request env confirm 0debug3: Ignored env TERMdebug3: Ignored env ITERM_SESSION_IDdebug3: Ignored env ITERM_PROFILEdebug3: Ignored env SHLVLdebug3: Ignored env OLDPWDdebug3: Ignored env GREP_OPTIONSdebug3: Ignored env GREP_COLORdebug3: Ignored env PAGERdebug3: Ignored env LESSdebug3: Ignored env LSCOLORSdebug3: Ignored env LS_COLORSdebug1: Sending env LC_ALL = en_US.UTF-8debug2: channel 0: request env confirm 0debug1: Sending env LANG = en_US.UTF-8debug2: channel 0: request env confirm 0debug3: Ignored env _debug2: channel 0: request shell confirm 1debug2: callback donedebug2: channel 0: open confirm rwindow 0 rmax 32768debug2: channel_input_status_confirm: type 99 id 0debug2: PTY allocation request accepted on channel 0debug2: channel 0: rcvd adjust 2097152debug2: channel_input_status_confirm: type 99 id 0debug2: shell request accepted on channel 0
SSH public key authentication works on LAN and not from WAN
ssh;osx;authentication;raspbian
Turns out I had enabled SSH on my Tomato router on the same port. My connection attempt had been to the router, not to my host. I changed the ports and all is good.