Creating a file where the owner and group is not root


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Creating a file where the owner and group is not root
# 1  
Old 06-06-2012
Creating a file where the owner and group is not root

Hi,

I'm the root user on my computer, but I'm writing a script that does a lot of file handling. Every time I create a file or directory it automatically requires root privileges. Is there a way I can just create a file that the user can access without a password?

For example in my script I write
Code:
$ unzip test.zip
$ ls -l
-rw-r--r--   root   root   text.zip 
-rw-r--r--   root   root   test1.txt
-rw-r--r--   root   root   test2.txt
-rw-r--r--   root   root   test3.txt

How do I unzip test.zip to user friendly permissions?

Thanks

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 06-06-2012 at 01:07 PM..
# 2  
Old 06-06-2012
First off, you just discovered one of dozens of reasons not to do everything on your desktop unix as root.


Code:
chmod 775 test.zip
su - someuser   # become some other user
unzip test.zip
exit  # go back to being root

make sure someuser has permissions to the destination directory so it can actually write files using unzip.

unzip -X will keep ownership and permssions, no "-X" allows the new user to create the files as the owner.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 06-06-2012
Root use

I'm not trying to do everything in root. The directory I'm working in is user friendly, but in my script I download a file from a website and it immediately puts root permissions on the file. Is there a way around this? Maybe if I try downloading the zip with the chmod 775 command you gave above I won't have to the root issues. I'll give it a shot. Thanks for the response.
# 4  
Old 06-06-2012
How can it put root permission on a file if you are not root?

I think you still have not learned what my collegue tried to tell you:

It is dead simple:

Do not work or use root account except for administration purpose...

When you download I am sure you were root...
This User Gave Thanks to vbe For This Post:
# 5  
Old 06-06-2012
How can I tell if I'm in root?
# 6  
Old 06-06-2012
What user did you log in as? If you logged in as root, you're root. sudo also runs things as root.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 06-06-2012
I'm logged in as diltsjr@diltsjr. Maybe I ran the script with a sudo command and that's why it downloaded the file as root.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX command to display Owner,Group,Root and Subdirectories list

Hi Team, Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path. I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this . Here is the sample result... (6 Replies)
Discussion started by: vasuvv
6 Replies

2. AIX

Files without owner and group

Dears it is normal that the below binaries stay without any owner and group I have checked it in many servers and the like the below /usr/lpp/bos.net/inst_root/etc/ipsec# ls -lrt total 248 -r-xr-xr-x 1 987 987 13589 Jun 29 2005 default_group -r-xr-xr-x ... (5 Replies)
Discussion started by: thecobra151
5 Replies

3. Emergency UNIX and Linux Support

To identify the group owner

If I have to identify the group owner of an AIX group, what is the command to be used. Example: there is an mqadm group, how do I find the owner of this group? Please help. (6 Replies)
Discussion started by: ggayathri
6 Replies

4. UNIX for Dummies Questions & Answers

Finding the group owner for a file

How would I find out who the group openers is of a file? For example: > ls -l myfile -rwxr-xr-x 1 myronp hawks 20125 Oct 20 20:50 myfile How do I return just hawks. I could do this with a series of cut or awk, but is there a more direct way. The ls -g is better, but still... (1 Reply)
Discussion started by: Dad4x
1 Replies

5. UNIX for Dummies Questions & Answers

Finding the Group Owner Name

Hi all, How can i find the group owner name...??? Thanks (4 Replies)
Discussion started by: mansahr143
4 Replies

6. Shell Programming and Scripting

Creating a control file for a group of files

Hi, We have almost 45,000 data files created by a script daily. The file names are of format-ODS.POS.<pharmacyid>.<table name>.<timestamp>.dat. There will be one data file like this for each pharmacy and each table.(Totally around 45,000) The requirement is to create a control file for each... (2 Replies)
Discussion started by: Maya_Pillai
2 Replies

7. UNIX for Dummies Questions & Answers

How to set the name of the group and the owner while creation of the file?

How to set the name of the group and the owner while creation of the file? -rwxrwxr-x 1 root sys 1202 Dec 5 2002 abc.awk like here i need to set the name of root and sys to xxx xxx Any help is appreciated. Thanks. (2 Replies)
Discussion started by: nehak
2 Replies

8. Shell Programming and Scripting

permission, owner and group

hello I search a script (ksh for Aix 5.3) to save all permissions, groups and owner for all files. Because we work much to change it, and a mystake ......! So i want execute this script to save/ execute permissions for all files. If you have this script, thank you for your help ;) best... (2 Replies)
Discussion started by: pascalbout
2 Replies

9. UNIX for Dummies Questions & Answers

Can't change owner and group of a linux file

Hi, I don't know how the owner & group of a login file in redhat linux 7.2 changed to bache like, -rwxr-xr-x 1 bache bache 17740 Jun 20 02:05 login I am trying to change the owner and group to root by using #chown root login #chgrp root login But i am getting the error ... (7 Replies)
Discussion started by: bache_gowda
7 Replies

10. UNIX for Dummies Questions & Answers

owner and group in Linux

I am bit unclear of how Linux was set in the real world, please advise me how it's supposed to be. When I log in as root and do a ls -l, I find: /boot, /, /var, /usr, /tmp, /home, /u01, /u02, /u03 and of of this partition is owned by root and the group also belong to root. Is that the way it's... (1 Reply)
Discussion started by: lapnguyen
1 Replies
Login or Register to Ask a Question