sudo cd riddle

73 views
Skip to first unread message

Dr. Parthasarathy S

unread,
Aug 21, 2010, 12:06:41 AM8/21/10
to iitdlug, sandeep kumar, Rajat Khandelwal
There was an innocent query about sudo in this list. (Never mind why
you want to do a sudo cd)

I tried it out and am frankly baffled.

Let us say I am NOT root, and I have a directory mydir.

cd mydir and it works fine (mydir has the same privileges like me,
since I own it).

sudo cd mydir and I get "sudo: cd: command not found" (after I give
root password).

OKay.. Now I do a su (and give the root password when asked).

Now do cd mydir and it works fine. Let my say that my default
privilege for all files/directories is 755.

I can't explain why this happens. Can some guru explain what is happening ?

Many thanks,

partha

Varsha Jaikumar

unread,
Aug 21, 2010, 12:20:42 AM8/21/10
to iit...@googlegroups.com
On Sat, Aug 21, 2010 at 9:36 AM, Dr. Parthasarathy S <drpa...@gmail.com> wrote:
There was an innocent query about sudo in this list. (Never mind why
you want to do a sudo cd)

I tried it out and am frankly baffled.

Let us say I am NOT root, and I have a directory mydir.

cd mydir and it works fine (mydir has the same privileges like me,
since I own it).

sudo cd mydir and I get "sudo: cd: command not found" (after I give
root password).

cd is a shell command, and not a program. So, when you try sudo cd, there is no program that can be launched, and so you get the error sudo: cd: command not found.

OKay.. Now I do a su (and give the root password when asked).

Plus, anyone can use sudo to enter a directory and manipulate files, so this calls for the use of su instead of sudo.

Now do cd mydir and it works fine. Let my say that my default
privilege for all files/directories is 755.

I can't explain why this happens. Can some guru explain what is happening ?

That's all I know, but I think it explains both confusions related to the use of su instead of sudo. Anything I am missing?

Many thanks,

partha

--
LUG@IITD - http://tinyurl.com/ycueutm



--
Varsha Jaikumar
Computer Science & Engineering (4th Year)
National Institute of Technology
Durgapur
Blog: http://varshamyspace.blogspot.com/



Sharad Birmiwal

unread,
Aug 21, 2010, 12:35:06 AM8/21/10
to iit...@googlegroups.com
> cd is a shell command, and not a program. So, when you try sudo cd, there is
> no program that can be launched, and so you get the error sudo: cd: command
> not found.

Correct. Also, there is a list of commands that can be run by certain
users and not ALL commands can be run. This is maintained through a
sudoers file. See "man sudoers". A brief overview from the manpage
follows -

"NAME
sudoers - list of which users may execute what

DESCRIPTION
The sudoers file is composed of two types of entries: aliases
(basically variables) and user specifications (which specify who may
run what).

When multiple entries match for a user, they are applied in
order. Where there are multiple matches, the last match is used
(which is not necessarily the most
specific match)."

Your distro may allow any sudoer to run any command but "cd" still
will not work since it is not an executable binary.


Sharad

vikash agrawal

unread,
Aug 22, 2010, 11:49:27 AM8/22/10
to Linux User Group @ IIT Delhi
or Simply use sudo nautilus and do whateva you want
Reply all
Reply to author
Forward
0 new messages