Can not open directory even if I sudo user

As root user I created a new user in my Ubuntu.

adduser isli

Than i granted to newly created user sudo permissions

usermod -aG sudo isli

Than switched to newly created user

su isli

in my isli user directory have projects directory which i want to open

sudo ls -al 

Give the following output

drwx------ 6 root root 4096 Feb 7 15:15 .
drwxr-xr-x 23 root root 4096 Jan 29 06:10 ..
drwxr-xr-x 4 root root 4096 Jan 18 09:43 projects

But while i am trying cd projects the output is permissions denied What i am doing wrong

4

1 Answer

Your user isli does not have any permissions for the directory you are in (.), which is the parent directory of your projects directory. This is because the directory . is owned by root and others do not have any permissions to it (the last --- in the mode indicator).

A solution is to give everyone read (r) and access (x) permissions for the directory:

sudo chmod o+rx .

Another option which you might prefer is to set the directory to be owned by the user isli:

sudo chown isli .

or if you want to also give isli the ownership of everything under that directory (such as the projects directory):

sudo chown -R isli .

(The -R switch stand for recursive.) Then isli will also be able to edit files in these directories, which you may be what you want.

Another suggestion

In fact, you might not want to do that, after all: you may be in root's home directory, and you probably want to keep that owned by root. The command su root did not change the current working directory, so if you started in root's home directory, which is normally /root, you would still be there. You probably want to keep that owned by root. You can display the current working directory using the command:

pwd

The solution you are looking for may be to move the projects directory into isli's home directory, which is normally /home/isli, but if you are not sure about that, you can, in most interactively used shells, refer to it by ~isli.

To set isli as the owner of the projects directory, to move it to isli's home directory, and finally to change to that directory, do:

sudo chown isli projects
sudo mv projects ~isli/
cd ~isli/projects

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like