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 08-27-2002, 08:29 AM   #1
rieta
LQ Newbie
 
Registered: Aug 2002
Posts: 4

Rep: Reputation: 0
user privileges


How do I find out if the currently logged in user has root privileges? Is there a command to do so? I have a .sh file which requires root privileges to correctly execute. How can I ensure this?

Please help
Rieta

Last edited by rieta; 08-28-2002 at 12:27 AM.
 
Old 08-27-2002, 09:18 AM   #2
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
run
w
or
who
 
Old 08-27-2002, 09:18 AM   #3
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
Or you can run
id
whoami

Last edited by neo77777; 08-27-2002 at 09:23 AM.
 
Old 08-27-2002, 03:50 PM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,532

Rep: Reputation: 132Reputation: 132
do u want to run this script yourself or do you want to allow other persons to run the script?
 
Old 08-28-2002, 12:32 AM   #5
rieta
LQ Newbie
 
Registered: Aug 2002
Posts: 4

Original Poster
Rep: Reputation: 0
This script will be executed bu other people. Before the script executes, it should be able to check if the currently logged in user has root privileges or not. I want to be able to perform this check through the script.

Regards,
Rieta
 
Old 08-28-2002, 05:13 AM   #6
nautilus_1987
Member
 
Registered: Aug 2002
Distribution: Slackware 8.1
Posts: 750

Rep: Reputation: 30
Many times you will need to change the file permissions. Perhaps to give someone else access to execute a file. To do this you need to use the "chmod" command. There are really two ways to chmod a file... one involves letters, +'s, and -'s which I think is way to confusing. The other way, (explained here) uses numbers. We assign each type of permission (r, w, and x) different numeric values.

r = 4
w = 2
x = 1

But you can use letters:
chmod u+rwx, g+r, o+r somefile
 
Old 08-28-2002, 09:44 AM   #7
Sfin
Member
 
Registered: Apr 2002
Location: Michigan
Distribution: Slackware 8.0
Posts: 197

Rep: Reputation: 30
well the UID of root is 0, so if you can have the script check the UID of the user, and if it is not 0, then have it print out a message like "You need to be root to run this".

I don't know what command will give you the UID of the user, so I can't help you there.
 
Old 08-28-2002, 10:00 AM   #8
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
I believe that 'cat /etc/passwd' would reveal the UID's of every user on the system.

HTH
 
Old 08-28-2002, 12:16 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
If you're more precise, "id greater or equal that (first user uid)" would show: [ "$(id -r)" -ge "500" ].

Btw, if a user sudo's over $(id -r) will reveal the current UID, whilst SUDO_UID will reveal his/her old UID, just so you know.
 
Old 08-29-2002, 12:48 PM   #10
Dexatrim
LQ Newbie
 
Registered: Aug 2002
Posts: 15

Rep: Reputation: 0
Also, check chmod and set user id scripts. From what you said, I don't think it's really what you want, but take a look.
 
  


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
Changing user privileges vikiugu Linux - Software 1 10-24-2005 05:55 AM
Root privileges for user ar1 Linux - Security 2 01-07-2005 10:33 PM
User with root privileges ShakyJake Linux - Newbie 2 06-18-2004 01:12 PM
Giving a User Root Privileges lawrencegoodman Linux - Newbie 4 12-23-2003 05:41 PM
MySQL problem with user privileges jriis Linux - Software 3 10-02-2003 10:20 AM


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