Results 1 to 15 of 15

Thread: Options for running a shell script as root in UNIX

  1. #1
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Options for running a shell script as root in UNIX

    Having finished a series of shell scripts to obtain things like kernel and networking parameters on various UNIX systems, I have just been advised that the software that will be used to launch them (a binary UNIX executable) will not be permitted to to run as root.

    So, what options do I have for running shell scripts as the 'root' user when the launching program is running as a normal non-root user?

  2. #2
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: Options for running a shell script as root in UNIX

    shell scripts as root? yeeeeees, there are ways, but they are VERY open to being compromised by hackers - no *nix admin would be happy to see his system hacked because your managers decided an app asking for appropriate permissions was too much work

  3. #3
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: Options for running a shell script as root in UNIX


  4. #4
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Re: Options for running a shell script as root in UNIX

    The problem is that the commands within my scripts require root access to run - the commands themselves are standard UNIX commands!

    I have tested the scripts standalone with a root logon on my test systems. I now need to integrate them into my companies software that the client has purchased. The client has advised us that the software will run as non-root. It is the software which will periodically execute my scripts but the scripts will be executed in a non-root shell, since the launching program will run as non-root, so the UNIX commands within the scripts will not run.

  5. #5
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: Options for running a shell script as root in UNIX

    Assuming said program uses the proper exec() calls, you can run the scripts with `sudo ./scriptname', and use visudo to edit your sudo configuration to allow the scripts to be run by the user of the program without password prompting. It's still not particularly ideal, but it works well. Personally I'd look into obtaining the kernel/network info you want from /sys and/or /proc without suid'ing to root at all.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  6. #6
    Throbbing Member
    Join Date
    Aug 2004
    Location
    Scotlandshire
    Posts
    633
    Thanks
    15
    Thanked
    9 times in 8 posts
    • 8bit's system
      • Motherboard:
      • MSI Z170A-G43 PLUS
      • CPU:
      • Intel i7-6700K
      • Memory:
      • 2x Kingston HyperX Fury Black (8GB)
      • Storage:
      • 1x Crucial MX100 512GB, 1x Western Digital Caviar Black 1TB (WD1001FALS)
      • Graphics card(s):
      • Sapphire AMD R9 390 Nitro
      • PSU:
      • Corsair RM650x
      • Case:
      • Corsair Carbide Air 540
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • LG 29UM67 29", 21:9, 2560x1080
      • Internet:
      • PlusNet Fibre

    Re: Options for running a shell script as root in UNIX

    Quote Originally Posted by aidanjt View Post
    Assuming said program uses the proper exec() calls, you can run the scripts with `sudo ./scriptname', and use visudo to edit your sudo configuration to allow the scripts to be run by the user of the program without password prompting. It's still not particularly ideal, but it works well. Personally I'd look into obtaining the kernel/network info you want from /sys and/or /proc without suid'ing to root at all.
    Note that sudo is not available as standard on some proprietary UNIX platforms. It's not installed on any of my Solaris 8/9/10 boxes at work.
    "shiro" - Windows 10 Home x64 :: Intel i7-6700K :: Corsair Hydro H90 :: MSI Z170A-G43 Plus :: 2x 8GB Kingston HyperX :: NVidia 3070 FE :: Corsair Force MP600 (1TB) :: Crucial MX100 (512GB) :: WD Caviar Black (1TB) :: Lite-On BD-ROM :: Corsair Carbide Air 540 (white) :: LG 32QK500 2560x1440 :: Logitech M500 :: Cherry KC6000 Slim ::

  7. #7
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: Options for running a shell script as root in UNIX

    That's true, even a number of Linux distros don't include the sudo package out of the box either. It'll just have to be a package dependency on the system he's developing if it's the route he wishes to take.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  8. #8
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Options for running a shell script as root in UNIX

    If it's merely a case of getting it done, you could su using EXPECT.
    To err is human. To really foul things up ... you need a computer.

  9. #9
    Senior Member
    Join Date
    Jun 2006
    Posts
    340
    Thanks
    22
    Thanked
    14 times in 14 posts

    Re: Options for running a shell script as root in UNIX

    Although if these are user machines, if you use the sudo option then the users will have root access any time they want - might be an issue...

  10. #10
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: Options for running a shell script as root in UNIX

    Quote Originally Posted by Templar87 View Post
    Although if these are user machines, if you use the sudo option then the users will have root access any time they want - might be an issue...
    Uh....... How do you figure that? The calling program of the scripts is a daemon.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  11. #11
    Senior Member
    Join Date
    Jun 2006
    Posts
    340
    Thanks
    22
    Thanked
    14 times in 14 posts

    Re: Options for running a shell script as root in UNIX

    Quote Originally Posted by aidanjt View Post
    Uh....... How do you figure that? The calling program of the scripts is a daemon.
    Well forgive me, but I can't see where the OP says that. I was under the impression that if you give a user sudo access, then s/he can open up a command prompt and enter "sudo <priviledged command>". If I'm wrong, I'm wrong

    Also you might want to work on the tone of your posts - I found that one a bit condescending.

  12. #12
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: Options for running a shell script as root in UNIX

    Quote Originally Posted by Templar87 View Post
    Well forgive me, but I can't see where the OP says that. I was under the impression that if you give a user sudo access, then s/he can open up a command prompt and enter "sudo <priviledged command>". If I'm wrong, I'm wrong
    Based on the context of the OPs description of the client's requirements, I'm guessing the program is at least daemonised, or worse case, called by a cornjob which can be configured to have it's own user.

    Quote Originally Posted by Templar87 View Post
    Also you might want to work on the tone of your posts - I found that one a bit condescending.
    My apologies.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  13. #13
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: Options for running a shell script as root in UNIX

    sudo access is granted per-command in /etc/sudoers, or overridden by the ALL command

  14. #14
    Senior Member
    Join Date
    Jun 2006
    Posts
    340
    Thanks
    22
    Thanked
    14 times in 14 posts

    Re: Options for running a shell script as root in UNIX

    Ah, well thank you guys - I understand now. Just ignore my ramblings, Taz

  15. #15
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: Options for running a shell script as root in UNIX

    It's quite alright, UNIX has several tens of thousands of pieces of software available for it, I don't expect anyone to know the nuances of each, much less from myself

    Questions like these are healthy and productive.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Deleting Linux..
    By AtomicFuse in forum Software
    Replies: 14
    Last Post: 07-07-2006, 11:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •