Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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!
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.