Question

Give user permissions to directory

I built an Ubuntu droplet and logged into the console as root and placed my files in a directory called jackssite. The path to the directory is /root/jackssite How do I give permissions to a user to ssh into the directory and look at the files and change what they may need to change?

I have users set up but if they use my root ssh login and password they get permission denied. Also, none of this is going to be a production site. I’m just trying out some things and sharing it with another user to help me get it right. What can I do to get them permission?


Submit an answer


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 3, 2023

Heya,

To allow a user to SSH into a directory and make changes, you’ll need to adjust the directory permissions and ownership. I’ll assume that you have a user called jackssite who needs access to the /root/jackssite directory.

Change the directory location: As a general rule, you shouldn’t give other users access to the /root directory because it’s the home directory for the root user and contains system-level configurations. It’s safer to move the jackssite directory to a non-root location, such as /home/jackssite. To do this, use the mv command:

mv /root/jackssite /home/

Change directory ownership: The next step is to change the ownership of the jackssite directory to the user jackssite. You can use the chown command for this:

chown -R jackssite:jackssite /home/jackssite

Set directory permissions: After changing the ownership, you also need to set the directory permissions so that jackssite has read, write, and execute permissions. You can use the chmod command for this:

chmod -R 755 /home/jackssite

This command will give jackssite (the owner) read, write, and execute permissions, and other users will have read and execute permissions.

Set up SSH access for jackssite: If jackssite doesn’t have SSH access yet, you need to set that up. You’ll create a .ssh directory in their home directory, then create an authorized_keys file where you’ll paste their public SSH key:

mkdir /home/jackssite/.ssh
chmod 700 /home/jackssite/.ssh
nano /home/jackssite/.ssh/authorized_keys

In the authorized_keys file, paste jackssite’s public key,. Then set the permissions for this file:

chmod 600 /home/jackssite/.ssh/authorized_keys
chown -R jackssite:jackssite /home/jackssite/.ssh

Now, the jackssite should be able to SSH into your server with their SSH key, and they’ll have access to the jackssite directory. They can navigate to it using cd /home/jackssite and then make the necessary changes.

ssh jackssite@Your_Droplet_IP

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel