# sudo shell settings and RCS



## xy16644 (Apr 5, 2014)

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:


```
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:



```
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:


```
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:


```
ci -u /etc/login.conf
```

and to check the file out I would run:


```
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?


----------



## SirDice (Apr 7, 2014)

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):

```
-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:
> 
> ```
> zfs send -R -i zroot@Daily_$yesterday zroot@Daily_$today | zfs receive -duv tank/fs
> ...



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.


----------



## xy16644 (Apr 7, 2014)

@SirDice: I think you are misunderstanding the first question. When I run `ls` using my own account it displays like this:


```
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:


```
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`.


----------



## Chris_H (Apr 8, 2014)

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


----------



## SirDice (Apr 8, 2014)

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.


----------

