I created user and generated key with this commands

root# mkdir /usr/share/foreman/.ssh
root# chmod 700 /usr/share/foreman/.ssh
root# chown user:user/usr/share/foreman/.ssh

root# su user -s /bin/bash
user$ ssh-keygen

And then tryed to copy key (on same server) between user and root

user$ ssh-copy-id [email protected]
user$ ssh [email protected]

But when tryint to ssh-copy-id root is asking for password. Don't know why.

Found on internet commenting UsePAM can fix the issue, but did not worked for me.

#UsePAM yes

I have also in my sshd_config this option allowed

PasswordAuthentication yes

1 Answer 1


The command

ssh-copy-id [email protected]

works by SSHing into the server and copying your SSH public key(s) to ~/.ssh/authorized_keys. If you don't already have public-key authentication, you will be asked for a password when SSHing into the server during this.

  • 1
    Problem is when I use password it wont accept it, even it's really proper one.
    – Delirium
    Commented Jan 4, 2019 at 14:14
  • 1
    You're trying to log into root with a password, by default this isn't allowed. On the server in /etc/ssh/sshd_config, what is PermitRootLogin set to?
    – steeling
    Commented Jan 4, 2019 at 14:16
  • there is commented #PermitRootLogin prohibit-password
    – Delirium
    Commented Jan 4, 2019 at 14:21
  • 1
    The default value is prohibit-password. This means that SSHing into a server as root is allowed, but password authentication is explicitly not allowed. Either you can change this to no (NOT recommended), or you can manually copy the public key part of your key (ending in .pub) into /root/.ssh/authorized_keys on the server.
    – steeling
    Commented Jan 4, 2019 at 14:25
  • Thank you for advice. Interesting is that, I tryed to login from differend machine and use ssh-copy-id and it worked. It's seems like not working only for that specific user.
    – Delirium
    Commented Jan 4, 2019 at 14:41

You must log in to answer this question.

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