sudo shell settings and RCS

I've got a couple of issue with sudo and RCS (Revision Control System) that I can't figure out.

First issue: When I am logged in as my own personal account and I (for example) do an ls -l the output looks as follows:

Code:
drwxr-xr-x    5 root  wheel     5B Jan 22 22:17 ./
drwxr-xr-x    5 root  wheel    13B Mar 30 09:51 ../
drwxr-xr-x   15 root  wheel    32B Jan 22 21:17 etc/
drwxr-xr-x  111 root  wheel   114B Jan 22 22:17 pkg/
drwxr-xr-x   45 root  wheel    45B Jan 22 21:18 ports/

(this is how I like it to be displayed)

Now when I do the same command but using sudo (ie: sudo ls -l) the output looks as follows:


Code:
etc     pkg     ports


How can I make sudo display and work the same way as though I was running the commands myself?

The other issue I have with sudo is when I try to pipe a command. An example is the following:

Code:
zfs send -R -i zroot@Daily_$yesterday zroot@Daily_$today | zfs receive -duv tank/fs

This would fail with an access denied but if I use su and become root then I can run the command. Is there a way to get commands like this to work with sudo?

The second issue I have is with RCS. When I built my new server I started checking files into RCS. In the directory the config file existed in I created a directory called RCS and then checked the files in as follows:

Code:
ci -u /etc/login.conf

and to check the file out I would run:

Code:
co -l /etc/login.conf

When you check the file in it changes the permissions to be read only for EVERYONE (including root). This prevents you from accidentally editing the file without checking it out first. In the beginning this worked perfectly and everytime I tried to edit a config file in RCS without checking it out first it would not save the file and I would have an access denied error.

Then I started using sudo and I find that when I edit a config file using sudo I can edit a config file WITHOUT having to check the file out! How is this so? Even if I log in as root I shouldn't be able to edit the file as it is in read only mode so why can using sudo allow changes to the file? What am I doing wrong?
 
xy16644 said:
How can I make sudo display and work the same way as though I was running the commands myself?
The difference is answered in ls(1):
Code:
     -A      Include directory entries whose names begin with a dot (`.')
             except for . and ...  Automatically set for the super-user unless
             -I is specified.
The other issue I have with sudo is when I try to pipe a command. An example is the following:
Code:
zfs send -R -i zroot@Daily_$yesterday zroot@Daily_$today | zfs receive -duv tank/fs
This would fail with an access denied but if I use su and become root then I can run the command. Is there a way to get commands like this to work with sudo?

If you have a command like sudo command1 | command2. Only command1 will run on sudo(1), the command2 will get run on your own account. If you want both commands to run on sudo(8) you have to do something like this: sudo "command1|command2". Note the quotes around the commands. The treatment of the pipe is because of the way the shell interprets a line.
 
@SirDice: I think you are misunderstanding the first question. When I run ls using my own account it displays like this:

Code:
drwxr-xr-x   15 root  wheel    32B Jan 22 21:17 etc/
drwxr-xr-x  111 root  wheel   114B Jan 22 22:17 pkg/
drwxr-xr-x   45 root  wheel    45B Jan 22 21:18 ports/

(forget the dots)

But when I use sudo ls it shows the output in a wide display...ie:

Code:
etc      pkg      ports

I basically want the sudo shell settings (if thats the correct term) to be the same as my own personal accounts shell settings.

If you have a command like sudo command1 | command2. Only command1 will run on sudo(1), the command2 will get run on your own account. If you want both commands to run on sudo(8) you have to do something like this: sudo "command1|command2". Note the quotes around the commands. The treatment of the pipe is because of the way the shell interprets a line.

Thats VERY helpful, thank you! I had no idea you had to use quotes when running multiple commands with sudo.
 
Last edited by a moderator:
I think the difference you experience issuing ls() as a user v as root, is because of the contents of .profile, .cshrc, and the shell associated with the root user account. As a quick experiment, you could ^D (<ctrl+d>, log out). Then log on as root, and issue ls() (no switches). If you still see a bare, inelegant listing. Then you will want to change the shell associated with the root user, and probably also want to "spiff up" .cshrc or whatever control/conf file is associated with your favorite shell, to suite your wishes. You might also want to look into sudoers. I don't use sudo() myself. But I think this'll get you what you're looking for.

HTH

--Chris
 
Keep in mind that sudo(8) clears a lot of the environment settings from the user for security reasons. See for example man sudoers | less -p "Command environment".

The best way is to edit both the user's and root's .cshrc and try to get the options to line up.
 
Back
Top