ssh-copy-id returning permission denied

When I try to use ssh-copy-id -i /root/.ssh/id_ed25519 root@192.168.134.140, it always returns Permission denied, please try again

I know that ssh-copy-id is a script in which scp and ssh is used. And scp to something like root@192.168.134.140 will fail. It makes sense to me.

But, after I unlocked the root user following the answer in this post: How to enable root login?, still it fails. Why is that and how can fix that: All I want is to ssh as a root user to 192.168.134.140 without password.

2

1 Answer

The link in your question points to enable Root login on your local machine. However, you might need to configure your openssh-server to allow Root logins.


But your primary issue is:

The file /root/.ssh/id_ed25519 is only accesible by root and that is why you get a Permission denied.

You could use

sudo ssh-copy-id -i /root/.ssh/id_ed25519 root@192.168.134.140`

However, you should not do that.
You don't need to use your local root to connect to a remote root user.

Either:

  • copy /root/.ssh/id_ed25519 to your normal user.
    sudo cp -t ~/.ssh/ /root/.ssh/id_ed25519* && sudo chown $USER: ~/.ssh/id_ed25519*
  • or create a new key with ssh-keygen

And then use ssh-copy-id with the newly created or copied one (without sudo).


Anyways,

You should not enable and use root login via ssh. Rather connect with a "normal" user and use sudo to elevate priviliges. You can also enable passwordless sudo for that user if you want that convenience.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like