2

I'm trying to copy a /id_rsa.pub to another machine with the command

cat .ssh/id_rsa.pub | ssh root@10.0.2.15 'cat >>
.ssh/authorized_keys'

but keep getting the error

sh: .ssh/authorized_keys: Is a directory

I created the directory with the following commands

mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys

The output from the command on the target machine

ls -l /root/.ssh

is "total 0"

5
  • Can you ssh to the remote machine as root, using password?
    – Arronical
    Nov 1 '16 at 11:46
  • yes, i can ssh with password Nov 1 '16 at 11:57
  • 1
    If you're logged in as root on your local machine, does ssh-copy-id root@10.0.2.15 give the same error?
    – Arronical
    Nov 1 '16 at 12:02
  • 1
    I've just noticed that your first command is missing the ~/ before .ssh/authorized_keys, is that the same as the command that you used?
    – Arronical
    Nov 1 '16 at 12:07
  • Is there a directory named ~/.ssh/authorized_keys on the remote machine?
    – terdon
    Nov 19 '16 at 16:13
5

The problem is that you've made a directory called ~/.ssh/authorized_keys. This is supposed to be a file. I'm not sure how this has happened, given that the commands you've listed should have just made the ~/.ssh directory and an authorized_keys file within it.

Remove the authorized keys directory on the remote machine, and replace with a file. Or even better, use the ssh-copy-id command from the local machine to create the file and add the key in one single command:

ssh-copy-id user@ip-address
7
  • Hi, thanks for the reply, i have also tried the ssh-copy-id command and got the same error. Nov 1 '16 at 11:36
  • Have you deleted the authorized_keys file?
    – Arronical
    Nov 1 '16 at 11:38
  • yes, ive tried a few different attempts over the past hour. Nov 1 '16 at 11:39
  • 1
    Could you edit your question to include the output of ls -l /root/.ssh on the remote machine.
    – Arronical
    Nov 1 '16 at 11:43
  • recreating everything and running that command again gives me the following Nov 1 '16 at 12:16

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.