Question

Setting up a new user using SSH

I followed the tutorial for setting up myself with SSH login which worked fine. I have another user I need to add as well but I am not sure how to go about doing that. I have his public key and added it to the droplet on creation. Droplet is running ubuntu 18.04. Any help would be greatly appreciated. I’ve looked through several other tutorials and documentation for this as well but I just can’t seem to find exactly what I am looking for. I don’t think I can set him up the same way I set it up for myself.


Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

KFSys
Site Moderator
Site Moderator badge
July 9, 2020
Accepted Answer

Hi @rconover,

You’ll need to create a new user and add the SSH keys there. I normally set and create their home directory at the same time.

i.e.

Create Home Directory + .ssh Directory

mkdir -p /home/mynewuser/.ssh

Create Authorized Keys File

touch /home/mynewuser/.ssh/authorized_keys

Create User + Set Home Directory

useradd -d /home/mynewuser mynewuser

Add User to sudo Group

usermod -aG sudo mynewuser

Set Permissions

chown -R mynewuser:mynewuser /home/mynewuser/
chown root:root /home/mynewuser
chmod 700 /home/mynewuser/.ssh
chmod 644 /home/mynewuser/.ssh/authorized_keys

Set Password on User

If you want to be able to log in as the user without an SSH key, setting a password will allow that, as long as PasswordAuthentication is enabled in /etc/ssh/sshd_config.

passwd mynewuser

You can check the users home directory by running:

echo $HOME

… while logged in as the user. If you echo $PWD, it’ll give you the current path to the directory that you’re currently in. So if I ran cd /home, running:

echo $PWD

… will give me /home. If my home directory is /home/mynewuser, then $HOME will give me that directory :-).

Regards, KFSys

Thank you very much! That clarifies a few things for me. I greatly appreciate it KFSys.

KFSys
Site Moderator
Site Moderator badge
July 14, 2020

Happy to help!

After all, this Q/A section is exactly for this!

I don’t see why you would chown root:root /home/mynewuserBy default, the command useradd mynewuser makes mynewuser the owner and group of the /home/mynewuser directory, which seems like a sensible default. Otherwise, you’ll need to add the execute bit to the permissions on /home/mynewusers in order for the authorized_keys file or any others to be accessible, which seems less ideal for security.

@kfsys

Omit this step on Ubuntu 22.04

chown root:root /home/mynewuser

I could not ssh in to the server because of this - error: Public key access denied.

Hi there,

I followed the steps listed above by KFSys and it looks like everything worked properly but when I tried to use the user&pass inside the Jetpack backup settings, it’s saying that the connection fails. Any thoughts?

Besides that, I’m using Transmit (file transfer tool) and after the steps above I cannot connect to the server with the root user anymore :PANIC:

KFSys
Site Moderator
Site Moderator badge
July 28, 2022

Hi @diegobechi,

Using the above to create your SSH key you shouldn’t be asked for a password.

If you however decided to use a password you need to enable it in your /etc/ssh/sshd_config. In there you’ll find the

PasswordLogin and set it to Yes.

Additionally, if you’ve lost access to your Droplet, check the following docs:

https://docs.digitalocean.com/products/droplets/how-to/recovery/recovery-console/

alexdo
Site Moderator
Site Moderator badge
July 9, 2020

Hi, @rconover

You can check out our existing tutorial on how to add users on Ubuntu 18.04 here:

https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-18-04

Additionally you can check that the user’s ssh key is present in the ~/.ssh/authorized_keys file and if not to add it there.

If the user needs a sudo access you can grant him access by following the tutorial.

Hope that helps!

Regards, Alex

Hi,

I’ve created a new user on 18.04 and .ssh folder has been created together with authorized_keys file.

I want to access it with Putty but it says "no supported authentication methods available (server sent: publickey).

I need that for Jetpack. I’m accessing the droplet with my SSH private key, no username is used.

How can I make this happen?

alexdo
Site Moderator
Site Moderator badge
September 8, 2020

Hello, @smailmilak

I will recommend you to check our existing tutorial on how to connect to your droplet using PuTTY on Windows.

https://www.digitalocean.com/docs/droplets/how-to/connect-with-ssh/putty/

and also on how to create ssh keys with PuTTY and Connect to a VPS:

https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps

Hope that this helps! Regards, Alex

Hi, so I managed to do that with PuttyGen. It’s easy if you what you are doing :)

So, now I want to give Jetpack RW access to /var/www/html/ where the Website files are located for Backup (I have digitalocean backup as well).

Problem is that this new user has R/O access only.

What is the exact chmod command to give R/W access to user ‘jetpackuser101’ and folder /var/www/html/ without breaking something?

KFSys
Site Moderator
Site Moderator badge
September 6, 2022

Well, the folder needs to have 755 permissions to have Read/Write access. That should be all.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.