[sudo-users] Problem with CD command while using sudo

Russell Van Tassell russell+sudo-users at loosenut.com
Fri Jul 29 15:13:28 EDT 2005


On Fri, Jul 29, 2005 at 10:20:19AM -0600, Bob Proulx wrote:
> Mousumi Kadham wrote:
> > Here is the situation. There are certain commands to be executed, files to
> > be edited in a protected directory which has a long path. Without sudo and
> > every one using root, administrators simply will do cd to the final
> > directory and do many things like editing a few files etc. However with
> > sudo, for every command, a long path has to be given and can quickly become
> > very irksome to the administrators. Hence the question about 'cd' with sudo.
> 
> The problem is that 'cd' is a built-in to the command line shell.
> 
>   type -a cd
>   cd is a shell builtin

This is highly OS/shell dependent... while some shells use an intrinsic,
others actually call a script or similar.  Since cd essentially, at some
point, works on the current shell, any call to sudo will fork a separat
 process that, when it dies, leaves the parent shell unaffected. (in a
nutshell, at least)

> [...]
>
> Another possibility would be to create a script to do the common
> tasks.  The script would embed all of those long and inconvenient
> paths and avoid the need for the users to type those in on the command
> line.  Think of the way that 'vipw', 'visudo', and others of that like
> work.  If you were editing a file you could create a script
> 'edit_myfile' or some such and allow it sudo access.

Agreed, this is pretty much what you'll have to do... or, as others have
said, create a unique group with browse (read) priviledges for your
directory structure.  Also, symlinks are beautiful things, too... ;-)

-- 
Russell M. Van Tassell
russell at loosenut.com

"We cannot be guilty of a greater act of uncharitableness, than to
 interpret the afflictions which befall our neighbors as punishments
 and judgments."                                       -- Joseph Addison



More information about the sudo-users mailing list