LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-03-2010, 07:54 AM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Slackware 14; CentOS; Vyatta
Posts: 372

Rep: Reputation: 33
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
 
Old 03-03-2010, 08:18 AM   #2
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 650

Rep: Reputation: 78
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

Last edited by bret381; 03-03-2010 at 08:20 AM.
 
0 members found this post helpful.
Old 03-03-2010, 08:30 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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.
 
Old 03-03-2010, 08:48 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by spoovy View Post
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 View Post
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
 
Old 03-03-2010, 09:01 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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
 
Old 03-03-2010, 09:16 AM   #6
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Slackware 14; CentOS; Vyatta
Posts: 372

Original Poster
Rep: Reputation: 33
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.
 
Old 03-04-2010, 01:49 AM   #7
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 03-04-2010, 02:07 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
You are both welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash printing pwd after cd now that I set CDPATH TiredOfThis Linux - Software 5 12-21-2009 02:15 PM
Samba MODIFY permission needs 'x' permission set in Linux? jlinkels Linux - Software 6 11-13-2009 09:30 AM
[SOLVED] sudo muck up, via xinitrc set up, and now startx different mark_alfred Linux - General 3 08-23-2009 09:54 PM
syntax error near unexpected token `set' `if ( $dirhome == "." ) set dirhome = `pwd dayanand patil Linux - General 6 01-21-2009 01:52 AM
Freespire-Want to set up password for sudo obnascar Linspire/Freespire 2 11-03-2006 12:21 PM


All times are GMT -5. The time now is 09:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration