LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-08-2013, 12:01 PM   #1
johnmccarthy
Member
 
Registered: Jul 2010
Posts: 64

Rep: Reputation: 1
Smile Setting umask for specific Users


I am using RHEL 6 and I want a certain user's (in the example user1) umask to read 022.
After entering the line umask 022 in the /home/user1/~./bash_profile the umask remains as 002, when user1 logs in. Do I need to modify the /etc/profile to eliminate the settings near the bottom which referece umask 002?

Everything I've read on the internet mentions simply add a line
umask 022
to there profile and there umask will adhere to the new line entry. They make it sound so simple. The user is using bash.

A million thanks in advance,
Johnny Mac
 
Old 02-08-2013, 12:37 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Files like .bashrc, .bash_profile, and .profile (also .login and few more in different shells) in user's home directory are called shell initialization files. Content within these initialization files is used to build up user's working environment and to set various shell and environmental variables. These files can be customized by user himself or by admin.

If these files are missing or not available in user's home directory, then systems check for default settings in /etc/profile.

FYI, umask is a command to set default permission of any newly created file/directory. For ease and convenience, it can be set in a user's shell initialization file(s). You can set the same the end of user's .bashrc or .profile file.

In your case, now any newly created file by the user1 will get a permission of 644 by default. BTW, I don't know your purpose of setting umaks manually, but your work sounds OK.

Good luck!

Last edited by shivaa; 02-08-2013 at 12:42 PM.
 
Old 02-11-2013, 07:03 AM   #3
johnmccarthy
Member
 
Registered: Jul 2010
Posts: 64

Original Poster
Rep: Reputation: 1
Smile A million thanks

I found the problem was I was entering the umask 022 in the wrong line. I entered the umask 022 under the line that says the below lines will be run upon login or startup and it took. A million thanks,
John
 
Old 02-11-2013, 08:38 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Great.

Juat edit .bashrc or .profile and add line umask 022 at the end. Then once source (or logout and login again) the file to take changes into effect.

Code:
~$ echo "umask 022" >> .bashrc
~$ source .bashrc
~$ grep 'umask' .bashrc
umask 022
Well, you can mark the thread as solved, if you think it has solved.

Last edited by shivaa; 02-11-2013 at 08:41 AM.
 
Old 02-12-2013, 08:24 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by johnmccarthy View Post
I am using RHEL 6 and I want a certain user's (in the example user1) umask to read 022. After entering the line umask 022 in the /home/user1/~./bash_profile the umask remains as 002, when user1 logs in. Do I need to modify the /etc/profile to eliminate the settings near the bottom which referece umask 002?
Changing the umask in /home/user1/~./bash_profile has the effect that you lose control as the user can easily change it back. /etc/profile should not be edited as at the end it executes scripts in /etc/profile.d/ (and using /etc/${SOMETHING}.d/ directories seems common these days), so to target only SH/BASH shells create a script "/etc/profile.d/umask.sh" like this:
Code:
if [ "$(id -gn)" = "user1" ]; then umask 022; fi
(Other environment variables you could check against are for example LOGNAME, USER or UID as in 'id -u').
 
Old 02-12-2013, 10:35 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
Quote:
Originally Posted by unSpawn View Post
Changing the umask in /home/user1/~./bash_profile has the effect that you lose control as the user can easily change it back. /etc/profile should not be edited as at the end it executes scripts in /etc/profile.d/ (and using /etc/${SOMETHING}.d/ directories seems common these days), so to target only SH/BASH shells create a script "/etc/profile.d/umask.sh" like this:
Code:
if [ "$(id -gn)" = "user1" ]; then umask 022; fi
(Other environment variables you could check against are for example LOGNAME, USER or UID as in 'id -u').
The user can always change the umask. Either from the command line, or through the appropriate shell ".rc" file in the users home directory.
 
Old 02-12-2013, 10:46 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Heh, true, I forgot that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
a specific umask for a folder nass Linux - Security 7 01-13-2014 11:08 PM
Umask a specific directory funyotros Linux - Server 2 12-11-2009 07:27 PM
Setting umask for incoming sftp users lensem Linux - Software 1 12-29-2008 03:15 PM
setting umask for all users and all sorts of logins sterrenkijker Debian 3 01-01-2006 05:19 AM
Mount specific umask on RH9.0? dirdej Red Hat 1 07-29-2004 04:18 PM


All times are GMT -5. The time now is 10:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration