Question

Problem with adduser, permission denied (publickey).

Posted April 13, 2020 552 views
Ubuntu 18.04

After creating a user (logged in as root) and trying to log in, I get “permission denied (publickey).”

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi there @tcp,

What you have to do first is:

  • SSH to the Droplet as root

  • Create a new user:

  • adduser your_user
  • Add the new user to the sudoers group:
  • usermod -aG sudo your_user
  • Copy the root account’s~/.ssh/authorized_keys to your new user’s home directory so that you could ssh as your new user:
  • rsync --archive --chown=your_user:your_user ~/.ssh /home/sammy

Note: change the your_user:your_user part with your actual username.

Hope that this helps!
Regards,
Bobby

  • Hi Bobby!

    Thanks for replying, I’m totally new at this so every suggestion is worth a lot to me!

    How do I copy the root account’s keys to my new user, easiest?

    Thx,
    Zeke

    • Hi there @tcp,

      You can do that by running the following command:

      • sudo rsync --archive --chown=your_user:your_user /root/.ssh /home/sammy

      Note: change sammy with your actual user name.

      Let me know how it goes!
      Regards,
      Bobby

      • It seems my answer got “arrested” xd

        No, that doesn’t change anything unfortunately.

        //Zeke

        • Hi there Zeke,

          Can you share the output of the following command:

          • ls -l /home/your_user/.ssh

          I think that maybe the permissions of the authorized_keys file are too open. You could try to change them with the following command and try again:

          • sudo chmod 600 /home/your_user/.ssh/authorized_keys

          And also the same for your .ssh folder:

          • sudo chmod 700 /home/your_user/.ssh

          Let me know how it goes!
          Regards,
          Bobby

Strange… still the same “Permission denied. (publickey).

  • Hi there @tcp,

    Can you share the output of the following command:

    • ls -l /home/your_user/.ssh

    I think that maybe the permissions of the authorized_keys file are too open. You could try to change them with the following command and try again:

    • sudo chmod 600 /home/your_user/.ssh/authorized_keys

    And also the same for your .ssh folder:

    • sudo chmod 700 /home/your_user/.ssh

    Let me know how it goes!
    Regards,
    Bobby

  • Also as a side note, make sure to use the reply button rather than posting your replies as answers, otherwise, I might miss your replies.

    You can also tag me to a reply by using the @ symbol followed by my username, just like this:

    @bobbyiliev

    That way I will receive an email and I would know that you’ve replied.

Submit an Answer