-2

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.

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89
ZhaoGang
  • 111
  • 1
  • 7
  • 1
    Did you try with `sudo`? Else you will not have access into `root` homedir. – Artur Meinild Mar 22 '21 at 13:09
  • 1
    In order to use `ssh-copy-id` without an **existing** key on the server, you will need to authenticate via password - as well as enabling root login, that requires that the sshd configuration `PermitRootLogin` is set (at least temporarily) to allow password authentication for root. Did you do that? – steeldriver Mar 22 '21 at 13:17

1 Answers1

0

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.

pLumo
  • 26,204
  • 2
  • 57
  • 87