1

I am trying to ssh from one Ubuntu box into an other Ubuntu box. Both are instances in the Google Cloud Platform and they have internal as well as external IPs.

I am trying to connect from lbox-a to lbox-b (lbox-a and lbox-b are hostname).

in lbox-a I have generated the SSH key for hduser1 using:

 ssh-keygen -t rsa -P ""

While adding public key into lbox-b

hduser1@lbox-a:~$ ssh-copy-id -i $HOME/.ssh/id_rsa.pub hduser1@lbox-b

I get the error:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hduser1/.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: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Permission denied (publickey).

I have tried replacing hduser1@lbox-b with root, an exisiting user, a non-existing user. And along with lbox-b I have also tried to use internal-ip and external-ip in its place.

sometimes I also get a time-out error:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: 
/home/ubuntu/.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: connect to host linuxbox-2 port 22: Connection timed out

Please guide me with this. I am not sure is it permission issue, port issue, some other reason with the box being hosted in Google Cloud Platform.

Thank you!

3
  • After running ssh-copy-id were prompt for a password? did you enter the remote-user password afterwards?
    – Yaron
    Commented Apr 6, 2017 at 5:21
  • 1
    You have to first enable password login at lbox-b, then copy the key. Then disable password login and leave only key login enabled.
    – ddnomad
    Commented Apr 6, 2017 at 5:55
  • I had not set password login into the remote server. Just curious - why do we need to set the password ? I have seen many tutorials/videos but never did I come across someone saying we need enable password loggin
    – kpython
    Commented Apr 7, 2017 at 3:00

1 Answer 1

4

The reason that ssh-copy-id fails is because it needs password authentication to be enabled in order to pass the ID. In the man page of that utility:

ssh-copy-id is a script that uses ssh(1) to log into a remote machine (presumably using a login password, so password authentication should be enabled

It's not possible for it to authenticate securely across in another way since the ID has not been copied over yet. If you could run that command without prior authentication then anyone could add their ID to the server.

You could certainly turn password authentication off after the ID had been successfully copied over if you didn't want password authentication enabled moving forward. Alternatively, you can manually copy and paste the ID over yourself between the two machines and then you don't need to use the ssh-copy-id utility.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .