LinuxQuestions.org
Review your favorite Linux distribution.
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 07-26-2016, 02:51 PM   #1
themosquito
LQ Newbie
 
Registered: Jul 2016
Posts: 3

Rep: Reputation: Disabled
Get login name for user


Hello,

I have a service account with a login name of "serviceaccount1' that I created using the following command:

useradd -d /home/serviceaccount1 -m -g root -G bin,daemon,sys,adm,disk,wheel -o -u 0 serviceaccount1

As you can see the user is created with the same uid as root. I have a bash script that I'm working on within which I need to display a prompt to root. Initially I had something like so:

if [[ `/usr/bin/logname` == "root" ]]; then

but this condition won't work for me since logname command will return root when run as root and when run as serviceaccount1. What command can I run within my bash script to check if the logged in user is root (loginname=root) that would filter out serviceaccount1 (loginname=serviceaccount1).

Hope this makes sense. Thanks in advance for your assistance!
 
Old 07-26-2016, 02:58 PM   #2
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
Could you check $USER or $HOME?
 
Old 07-26-2016, 04:02 PM   #3
themosquito
LQ Newbie
 
Registered: Jul 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
Could you check $USER or $HOME?
Thank you for the quick response.

SUSER returns root for both accounts.
I guess worst case we can use $HOME to parse the username out of the directory or something...but there's no linux command that I can run that would return 'root' for the root account and 'serviceaccount1' for the serviceaccount1 account? Thanks!
 
Old 07-26-2016, 04:21 PM   #4
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
Not that I know of, because what you're doing is very non-standard and generally frowned upon. Whatever it is you're trying to accomplish by creating a second root account with a different name, the chances are very high that there's a better way to do it than this.
 
Old 07-26-2016, 04:39 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
The user name is almost exclusively used for authentication only, after authentication the entire system is built around UID as the user identifier.

User name is subsequently derived by a reverse lookup from the UID in the passwd file. If you have two user names with the same UID, that lookup will produce the first name encountered, not necessarily the one used to authenticate the session. It is implicit in the Unix/Linux design that there is only one user with UID 0 (or any other UID).

Having two users with UID 0 creates confusion and potentially breaks many things... you probably shouldn't do that.

Last edited by astrogeek; 07-26-2016 at 04:43 PM.
 
Old 07-26-2016, 04:46 PM   #6
themosquito
LQ Newbie
 
Registered: Jul 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for both for the responses. What we're trying to achieve is create a service account with root level provileges that can be used by a new product we're implementing that manages unix account passwords. The documentation for creating the service accounts lays out two approaches one of them being to create a user with the same uid as root. My question about the script relates to if we proceed with this approach. But based on your responses this is not the way to go. The other approach in the documentation for creating the service account is to create an account with sudo privs. There's a separate issue we're facing when we tried to go down this path that involves sudo access being locked out after a certain number of successful sudo attempts. I guess I'll create a new thread on this since it's a separate issue.


Thanks!
 
Old 07-28-2016, 11:11 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by themosquito View Post
What we're trying to achieve is create a service account with root level provileges that can be used by a new product we're implementing that manages unix account passwords. The documentation for creating the service accounts lays out two approaches one of them being to create a user with the same uid as root.
What's "Plan B"?
 
  


Reply



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
RHEL 6 - Upon GUI Login Present successful and unsucessful User Login johnmccarthy Linux - Newbie 2 07-24-2013 12:38 PM
Ubuntu/AD/KRB5/LDAP/NIS able to use domain user login with putty, unable in gui login Nitroglycerine Linux - Server 0 06-28-2012 04:17 AM
how do I set different permission for single user for sudo login n direct login? bhaveshvv109 Linux - Security 2 11-08-2011 08:23 PM
Gnome: Cannot login as default user, sends back to login, works as root Danny-T Linux - Newbie 2 05-27-2006 03:44 AM
Crazy blank dialog boxes and windows at login. Can't login as user soren625 Linux - General 2 08-11-2004 06:30 AM

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

All times are GMT -5. The time now is 09:33 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