RE: Files & permissions

"Andreas Lund" <[email protected]> Sun, 21 Jul 2004 15:42:05 -0000
Newsgroups gmane.linux.redhat.release.valhalla
Message-ID <[email protected]>
Wed, 21 Jul 2004 15:51:31 +0100, "Harry Hambi" <[email protected]> wrote:
> Understand....lets say there's only one file I wish only read access
> to,I don't want them logging on as me, can I create a separate log on, &
> give them read only access to this one file?.

You can do this in a number of ways, but the simplest (if there are only the
two of you) is to grant "everyone" read access to the file. Incidently, this
is usually the default when you create a file:

[root@hermes root]# touch my_file       
[root@hermes root]# ls -l my_file 
-rw-r--r--    1 root     root            0 Jul 21 17:20 my_file

But let's say I have a file with the following permissions set:

[root@hermes root]# ls -l my_file      
-rw-------    1 root     root            0 Jul 21 17:20 my_file

As you can see from the privilege flags, Only the root user has read/write
access to this file. I can grant read access to everyone like this:

[root@hermes root]# chmod +r my_file 
[root@hermes root]# ls -l my_file     
-rw-r--r--    1 root     root            0 Jul 21 17:20 my_file


Another way to do it is if you create a group, make the other user member of
that group, and then change group ownership and permissions of the file. Like
so: (I'll call your friend "steve" if that's okay with you ;-)

[root@hermes root]# ls -l my_file      
-rw-------    1 root     root            0 Jul 21 17:20 my_file
[root@hermes root]# groupadd friends
[root@hermes root]# usermod steve -G steve,friends
[root@hermes root]# chgrp friends my_file
[root@hermes root]# chmod g+r my_file
[root@hermes root]# ls -l my_file      
-rw-r-----    1 root     friends         0 Jul 21 17:20 my_file


Or you could just change group ownership of the file to his personal group:

[root@hermes root]# ls -l my_file      
-rw-------    1 root     root            0 Jul 21 17:20 my_file
[root@hermes root]# chgrp steve my_file
[root@hermes root]# chmod g+r my_file
[root@hermes root]# ls -l my_file      
-rw-r-----    1 root     steve           0 Jul 21 17:20 my_file


As you can see, there are a lot of different ways to solve this, which one you
choose depends on the circumstances. Will other users need access to the same
file(s) in the future? What's in the file? How is the file used, is it static
or is it updated by you or perhaps a program? Some programs are picky about
file ownership and permissions.

In the end, to pick the perfect solution you need to understand the UN*X file
permission model. Unfortunately it's quite primitive compared to what you'll
find in, say, Netware or even Windos today. For that kind of fine-grained
control you need to use server software like Samba or an FTP server. 


ps. 

Yes, I usually do everything as "root" on my servers. 
It's a bad habit, I know ;-)

--
Andreas Lund ([email protected])
Tel: +47 90.07.71.62 / +47 63.88.33.56
Ano-Tech Computers (http://www.atc.no/)
** He had a baseball bat and I was tied to a chair. 
** Pissing him off was the smart thing to do.  -- Max Payne