LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 01-24-2017, 10:09 AM   #1
sunilchand
LQ Newbie
 
Registered: Jan 2017
Posts: 12

Rep: Reputation: Disabled
Why a user isn't opening by its own name while giving it root privileges ?


Hello all.Hope you are doing great! Coming into a point.. I have changed a user's privileges in Rhel 6.6 by making changes in the /etc/passwd file and setting particular user's UID and GID values to "Zero"(as it is for root) so that , that particular user perform some important tasks like .. changing other user's password ..etc . After changing it. When I type su (switch user) command followed by that particular username, it is opening as root not as a that particular user.. Please enlighten me on this topic.Thanks

Last edited by sunilchand; 01-24-2017 at 11:00 AM.
 
Old 01-24-2017, 10:19 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Code:
man su

       When called without arguments, su defaults to running an interactive
       shell as root.
 
Old 01-24-2017, 10:34 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
One would also question your motives behind touching the /etc/passwd file? Also, do you understand what the 'U' in UID stands for, because if you do, you would know that assigning it to another user is highly problematic and violating the constraint.
 
Old 01-24-2017, 10:45 AM   #4
sunilchand
LQ Newbie
 
Registered: Jan 2017
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Code:
man su

       When called without arguments, su defaults to running an interactive
       shell as root.
i already typed: su username
 
Old 01-24-2017, 10:48 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by sunilchand View Post
i already typed: su username
That's not what you said in your first post.
Quote:
Originally Posted by sunilchand View Post
When I type su (switch user) command, it is opening as root not as a that particular user..
As is also said, messing around with /etc/passwd to achieve this is a BAD THING and you WILL break things.

If you wish to let another user run certain commands as root then make use of
Code:
sudoers/sudo
 
Old 01-24-2017, 10:52 AM   #6
sunilchand
LQ Newbie
 
Registered: Jan 2017
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
One would also question your motives behind touching the /etc/passwd file? Also, do you understand what the 'U' in UID stands for, because if you do, you would know that assigning it to another user is highly problematic and violating the constraint.
Yes I know dear... But as I am new to Linux and was experimenting it on my own Laptop to learn how it works.. That's why I was asking about it.. The main motive for doing this, just to learn how it works.. Nothing else.
 
Old 01-24-2017, 11:02 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Safety First Kids!
Code:
sudo cp /etc/{passwd,passwd.bak}
 
Old 01-24-2017, 11:15 AM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by sunilchand View Post
I have changed a user's privileges in Rhel 6.6 by making changes in the /etc/passwd file and setting particular user's UID and GID values to "Zero"
Don't do that. That's not how you "change a user's privileges", all it does is screw up the UID/username mapping as you've seen first hand. Regular users aren't root for a reason. If you want to be root, su to root.
 
Old 01-24-2017, 11:23 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
In addition, when you change the UID/GID to zero and when you login for all effective purposes that user is root. As suggest by others if you want to give a regular user a particular privilege you should use sudoers
 
Old 01-24-2017, 11:43 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Sudo: you're doing it wrong - PDF @ 171 pages.
Sudo: you're doing it wrong - YouTubeVid @ 1h:11m

Run, don't walk.
 
Old 01-24-2017, 12:41 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Originally Posted by sunilchand View Post
Yes I know dear... But as I am new to Linux and was experimenting it on my own Laptop to learn how it works.. That's why I was asking about it.. The main motive for doing this, just to learn how it works.. Nothing else.
As others have pointed out, this is not walking before running, this is flying at lightspeed straight for the sun.
It would also seem to be a very unusual first thing to want to experiment on.

As suggested, either use su as designed or investigate the sudo option
 
Old 01-24-2017, 01:53 PM   #12
Rickkkk
Senior Member
 
Registered: Dec 2014
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Quote:
Originally Posted by sunilchand View Post
Hello all.Hope you are doing great! Coming into a point.. I have changed a user's privileges in Rhel 6.6 by making changes in the /etc/passwd file and setting particular user's UID and GID values to "Zero"(as it is for root) so that , that particular user perform some important tasks like .. changing other user's password ..etc . After changing it. When I type su (switch user) command followed by that particular username, it is opening as root not as a that particular user.. Please enlighten me on this topic.Thanks
.. I echo the warnings and advice above, however, in response to your question, the UID (user ID) and GID (group ID) are the >>>real<<< underlying values of the user and group IDs, the way the system recognizes them. So, having made the (inappropriate) changes you described to the /etc/passwd file, you have effectively told your system that when you use the username you are referring to, either directly or through the su command, you are indeed using root.

As suggested by many already, the sudo command is the way to go for most cases requiring alternate user privileges.

Hope this helps ! :-)
 
Old 01-24-2017, 03:55 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Expanding on Rickkkk, usernames are just human friendly labels (see also eg DNS names).
In reality its all done with numbers.... and 1st entry in /etc/passwd with uid/gid = 0 is 'root'.

As mentioned above, don't do that
Use either su or sudo depending on what you want .....
 
Old 01-25-2017, 04:15 AM   #14
sunilchand
LQ Newbie
 
Registered: Jan 2017
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Expanding on Rickkkk, usernames are just human friendly labels (see also eg DNS names).
In reality its all done with numbers.... and 1st entry in /etc/passwd with uid/gid = 0 is 'root'.

As mentioned above, don't do that
Use either su or sudo depending on what you want .....
Yes, I understand that it's not good to change uid and gid value. It's rather to choose "Sudoers" file for the same.I have changed privilege of any user by editing this User1 ALL= (ALL: ALL) ALL.. Something like that.. But I want this command for some specific command not for all command.. How to do that?
 
Old 01-25-2017, 05:20 AM   #15
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Maybe if you now tell us what you actually want to do, someone will be able to answer your question?
 
  


Reply

Tags
privileges, root



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
usr added to wheel group but isn't allowed root privileges jus71n742 *BSD 7 06-11-2009 04:52 PM
Giving a user Admin Privileges wildcat22 Ubuntu 4 08-07-2008 07:12 AM
Linux - How to add a new user with the same root/super-user's privileges? asgarcymed Linux - General 8 12-23-2006 07:45 PM
Giving root privileges to another user BlackJackal Mandriva 5 10-19-2005 01:03 PM
Giving a User Root Privileges lawrencegoodman Linux - Newbie 4 12-23-2003 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 PM.

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
Open Source Consulting | Domain Registration