LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can't set PWD despite having sudo permission set. (https://www.linuxquestions.org/questions/linux-newbie-8/cant-set-pwd-despite-having-sudo-permission-set-792866/)

spoovy 03-03-2010 07:54 AM

Can't set PWD despite having sudo permission set.
 
As user lukas, who is listed in 'sudoers' with the same rights as root (ie ALL=(ALL)) I can't cd 'into' dir /var/spool/cron:


(from sudoers)
root ALL=(ALL) ALL
lukas ALL=(ALL) ALL



As root i can cd into it no problem. As lukas, i get permission denied, and if I try 'sudo cd cron' I get an error saying command 'cd' is not recognised.

file permissions as follows -

drwxr--r-- 2 root root 4096 2010-03-03 12:56 cron


What have i done wrong?

Thanks in advance

spoov

bret381 03-03-2010 08:18 AM

you shouldn't have to sudo to enter a directory, only to make changes to a file

so

cd cron

should get you in the directory

druuna 03-03-2010 08:30 AM

Hi,

A normal (= none root) user cannot cd into the cron directory given in the example in post #1.

The directory only has read permissions on the group and world (execute permission are also needed to cd into it).

Using sudo won't change that fact (unless you sudo to root).

Hope this helps.

zhjim 03-03-2010 08:48 AM

Quote:

Originally Posted by spoovy (Post 3883883)
As root i can cd into it no problem. As lukas, i get permission denied, and if I try 'sudo cd cron' I get an error saying command 'cd' is not recognised.

cd is a shell command so sudo can't find it cause it's not in the filesystem

Quote:

Originally Posted by spoovy (Post 3883883)
file permissions as follows -

drwxr--r-- 2 root root 4096 2010-03-03 12:56 cron


What have i done wrong?

Thanks in advance

spoov

I'm not quite sure like my pre poster (druuna) that execution bit is needed to cd into a directory. At least to view the contents of a directory only read permission is needed. If I find time to see if I can find out something about it. But in the meanwhile you can test yourself with
Code:

chmod o+x /var/spool/cron
and then cd into it.

On a side note. Do you absolutly have to cd into that directory? Why not for example just do a
Code:

sudoedit /var/spool/cron/filename
or
Code:

sudo cat /var/spool/cron/filename

druuna 03-03-2010 09:01 AM

Hi,

@zhjim: Permissions on a dir work differently then on a file.

Maybe this will help:
Quote:

The next nine letters represent "what can be done"

To an ordinary file:

r means read -- viewing of file contents
w means write -- changing and storing of file contents
x means execute -- permits the execution of the file

r is also needed to execute a script because the shell has to interpret the commands inside it
r is not needed to exectute a binary file since it is simply loaded into memory and executed

To a directory:

r permits viewing of the directory contents
you can view the contents of the directory (remember a directory is just a file)
To use the ls command without any arguments, you don't need execute access.
w permists altering the directory contents
adding or deleting a file
x permits a user to be in the directory (to "cd" to a directory)
you don't need read acccess to cd to a directory
to run any command that operates on the files in the directory, you need read as well
Taken from Unix/Linux File Permissions

spoovy 03-03-2010 09:16 AM

Thanks druuna and zjhim. It looks like you do need execute permission to cd to a dir. I thought you only needed read permission.

zjhim - no I suppose i didn't need to cd into it, its just a habit to always cd one dir at a time and always list contents. Keeps me aware of where i am in the filesystem.

zhjim 03-04-2010 01:49 AM

Thanks druuna for the clarification.

I have the same habit spoovy but something I just make my life a bit more complicated as it's need to be ;)

druuna 03-04-2010 02:07 AM

You are both welcome :)


All times are GMT -5. The time now is 01:41 PM.