0

I have a local laptop MacOS hence called localmac having macuser that needs to be controlled (by firing ssh commands) by a remote server hence called remotelinux having linuxuser.

On my localmac i m able to successfully ssh linuxuser@remotelinux

On my localmac I did post tunneling using the below command:

ssh -fnN -R 4444:localhost:22  linuxuser@remotelinux

Now, on my remotelinux i try to copy the keys using the below but I get the error:

$ ssh-copy-id -p 4444 macuser@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/linuxuser/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: ERROR: ssh_exchange_identification: Connection closed by remote host

I understand the above failed, however I try to fire the hostname command on remotelinux like below:

[linuxuser@remotelinux ~]$ ssh -p 3334 macuser@localhost 'hostname' -vvvv
ssh_exchange_identification: Connection closed by remote host
[linuxuser@remotelinux ~]$ ssh -p 3334 macuser@localhost -vvvv
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolving "localhost" port 3334
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [::1] port 3334.
debug1: Connection established.
debug1: identity file /home/linuxuser/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
ssh_exchange_identification: Connection closed by remote host

On the localmac i found the below message printed for each ssh command i fired from remotelinux

SSH tunneling: connect_to localhost port 22: failed

Can you please suggest How can I get this to work?

1
  • Could it be that sshd is not listening at port 22 on localmac? Confirm this by running ss -nltp | grep 22 or ss -lntp | grep ssh as root. Feb 12, 2021 at 13:39

1 Answer 1

1

Remote login is disabled by default on a MacOS laptop, hence SSH fails. Go to preferences and enable it.

1
  • Correct answer @Bruce Malaudzi Thank you!
    – Ashar
    Feb 12, 2021 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.