Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The general issue is that if I create or modify any file or directory with sudo then it seems that I'm unable to create and modify this file or directory further as any other user than sudo. The rest of this below is me elaborating on that issue.

It seems to me that I need to be sudo in order to do some things in ubuntu, for example, I can't seem to mount a server without being a super user, so I'm mounting a server like this:

sudo smbmount //server-address /media/netmap -o user=username,domain=domainname

and I've tried tacking on this bit about the user id and group id, but to no avail

 sudo smbmount //server-address /media/netmap -o user=username,domain=domainname,rw,uid=zallenlab,gid=zallenlab

I am using this line from the terminal because I need to enter a password, by password for the server for one thing, not the sudo password, and I can't seem to get this to work by modifying the fstab file, even if I explicitly include my password in the file. And from the terminal, removing sudo, or trying just 'mount', neither of these things work for me, just the line that I pasted above (both commands have the same result, tacking on that bit about uid doesn't do anything).

Additionally, Ive noticed something weird, that when I use the sudo command to do something like to try to create an archive of a directory, or to run rsync to do some updates, this changes the permissions of all associated dirs to being accessible to sudo only. That is really weird to me. What is the use of this type of system? I must be doing something really wrong here.

This is a problem for me because then everything I do after this point needs to be sudo in order to access files, modify them, delete, or make new files and/or folders. That is a huge pain in the ass. I run into similar issues with calling programs from scripts. It seems that sometimes if I call a program from a script it will not have read and write permissions of some files in some places. I think this is all stemming from the sudo issue. I am the only user of this machine. I think in most cases there really is one user per machine. I'm on the verge of just figuring out how to log on as a sudo account permanently from start to finish, but I see all these warnings about that not being a good idea and that I should ask the ubuntu community before doing this, so I'm posting my question now. Please help.

Basically, I want to be able to run scripts that can do very basic things like back up files (make zip archives of directories both locally of local files, and on a server of the server files), update files by comparing directories from local to server folders, and I am moving around and creating quite a bit of files through matlab as well. I don't think it's so complicated what I'm trying to do, but I'm having a real hard time sorting out this permissions issue. Seems like it is coming up with everything that I do.

Thanks.

share|improve this question
add comment

2 Answers

Using sudo means you are running as the root user for that command. Any files or directories you create will be owned by root. If you want to give your normal user access, you need to change the permissions and/or ownership

something like chown <yourusername>:<yourgroupname> <filename>

when mounting the smb server, try setting the ownership/permissions on the mountpoint first, before mounting the drive.

share|improve this answer
    
Thanks for responding. Maybe you're right that this was an issue. I did this, changed the permissions for the mountpoint. However, I still cannot mount without using the sudo command. I don't know why. The same line without sudo does not work. This does not work: "smbmount //server mountpoint -o user=username,domain=domainname" but it does if I put sudo in front of it. If I use sudo then it reassigns root ownership of the directory. Also, I'd rather do this all through the fstab file. I've tried a couple different lines and nothing is working I think because for some reason sudo is required. –  Dene Farrell Jul 27 '12 at 19:03
add comment

General Unix Permissions Information

This is the fundamental way any POSIX (Unix/Linux/others) work. Everything is done under a user. Whenever you make a directory it inherits the owner and default permissions set in the umask of that owner. Whenever you do something with sudo, you basically do the operation not with your user but with the user "root" - the "Administrator" in Windows.

sudo is just a shortcut for:

  1. Login as "root".
  2. Run the command.

In Windows terms - "Run as Administrator".

Having that in mind, it should be clear that you should not need to use sudo for anything related to your user. It should be only needed for use with stuff owned by the "root" user. Stuff such as the system configuration in /etc/, mounting drive volumes etc.

Now, there are things that are typically done by "root" but sometimes need to be done by a user. To allow this, there are groups who are given permissions to that. For example the group "disk" is allowed to access hard drives in raw mode - i.e. like "root". If you want to be able to that with your own user - you simple have to add yourself to that group like so:

sudo adduser [yourself] disk

Obviously only root can do that so you need sudo.

This is generally how permissions work in POSIX OSes. There is more to it but this should answer your particular issue. How to solve the particular SAMBA problem is a separate topic.

You can find more on Unix permissions in this lecture on Unix including Unix permissions from University of Toronto.

Mounting SAMBA shares as non-root

Now about your particular issue with SAMBA - there is nicely described way to do it in the Samba Client Guide. Note that above that on the same page there are also other ways to do it via UI.

share|improve this answer
1  
hey thanks for the reply lightrush, I'll keep this approach on the backburner as a last ditch work around, but I think there should be some simple way for me to mount a server, read and write files, and such things all without the root settings. I'm trying to stay away from this root user approach because every time I use sudo to create something I have to go and chown it back to the regular user. –  Dene Farrell Jul 27 '12 at 19:13
    
I've also added a link to a good guide on how to do what you want with SAMBA without root. Hope that helps. :) –  lightrush Jul 27 '12 at 23:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.