I am trying to connect to a server which already established a remote ssh connection to my client by running the following on server:
ssh -R :8080:localhost:22 -p 22 clientUser@clientIP
when I try to connect to the server by running the following on the client side:
ssh -p 8080 localhost
I am getting asked for a password as:
clientUser@localhost's password:
both connections should be able to establish via public key (the remote port forwarding ssh already can do this with no problem.)
furthermore in /var/log/auth.log on server shows:
Invalid user clientUser from 127.0.0.1 port 39768
which suggests that the server sees this as kind of a loopback connection?
the client OS is MacOSX Mojave and the server side is Ubuntu 18.04 LTS.
If I try to remote forward the connection from the client to any port other than 22 on the server I am getting
ssh_exchange_identification: Connection closed by remote host
I appreciate your kind help!
thanks to Chris in comments.
the problem was I had to
ssh -p 8080 serverUser@localhost
by default
ssh -p 8080 localhost
is the same as
ssh -p 8080 ${USER}@localhost
and uses the current user from the environment. This will results in an invalid user message by the server.