I am trying to set up an personal SSH server behind a router and be able to connect to it with my laptop. I have tried several guides but nothing has worked so far. I have
- enabled port forwarding on my router, directing all traffic on the port XXXX to my server's port 22.
- started the
sshd
daemon on my server (default listening on port 22), and verified port 22 on my server was open. - used
ssh-keygen
on my laptop to generate a key pair, then transferred it via usb to the server asmy_key.pub
. I left the password field blank during the keygen creation. - On the server, I
mkdir ~/.ssh
andcat my_key.pub >> ~/.ssh/authorized_keys
. On the laptop Imkdir ~/.ssh
and move my private keymy_key
in there.
My public IP is YYY.YYY.YYY.YYY. My local IP for the server is 192.168.1.73.
When I try
ssh root@YYY.YYY.YYY.YYY -p XXXX -v
I get that the connection is refused, with no other debug messages. The same thing happens without the port specification.
When I try
ssh root@YYY.YYY.YYY.YYY -v
I get that I am greeted with a password field, which no password works for:
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.1.73 [192.168.1.73] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/xps/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.3p1 Debian-1
debug1: match: OpenSSH_7.3p1 Debian-1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.73:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:0wIYI/LCJOSgjJMN9uiinKC5GVwNyH7cVf1CeqnAQEs
debug1: Host '192.168.1.73' is known and matches the ECDSA host key.
debug1: Found key in /home/xps/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/xps/.ssh/id_rsa
debug1: Trying private key: /home/xps/.ssh/id_dsa
debug1: Trying private key: /home/xps/.ssh/id_ecdsa
debug1: Trying private key: /home/xps/.ssh/id_ed25519
debug1: Next authentication method: password
root@192.168.1.73's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
root@192.168.1.73's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
root@192.168.1.73's password:
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
Permission denied (publickey,password).
Specifying the port in this option gives me another connection refused. I am confused by what is going wrong here!
Thank you.
EDIT Here is the debug info for the rest of the scenarios:
OpenSSH_7.3p1, OpenSSL 1.0.2h 3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to YYY.YYY.YYY.YYY [YYY.YYY.YYY.YYY] port XXXX.
debug1: connect to address YYY.YYY.YYY.YYY port XXXX: Connection refused
ssh: connect to host YYY.YYY.YYY.YYY port XXXX: Connection refused
.ssh/config
entry remapping things? – Stephen Harris Sep 06 '16 at 00:10~/.ssh
..., do you mean/root/.ssh
since you are trying to login as root? And isPermitRootLogin
set toyes
in sshd_config on the server side? – Paul Nordin Sep 06 '16 at 00:11Yes, Paul I mean those to be the same.
– ardunn Sep 06 '16 at 01:03PermitRootLogin
is set toprohibit-password
, should I change that? I mean I dont want this server to be accessible via crackable password, so how could I circumvent that?PasswordAuthentication
tono
if you want to prohibit all SSH access via password. – Paul Nordin Sep 06 '16 at 01:32