LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-08-2019, 04:32 PM   #1
makupl
LQ Newbie
 
Registered: Sep 2013
Posts: 23

Rep: Reputation: Disabled
SUID more explanation needed


I'm trying to understand SUID functionality.

So what I try is to create script.sh which modifies let say file a.txt.
The script.sh is owned by specific user, let say test1 and group test1. Also file a.txt is same user and group. Now I do not allow to write for other users to file a.txt, however I set rws------ on script.sh (SUID is set)
File a.txt has permissions rwxr--r--. Now when I execute script.sh as user test2 I got permission error on a.txt.
I understood execution of script.sh is fired from user test2 but as it was run by user test1 who actually has write permisions to a.txt file.
Must be I understand it wrongly. I understood user test2 can't modify a.txt file directly but using script.sh may change accordingly if script.sh requires it.
 
Old 09-08-2019, 05:00 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by makupl View Post
I'm trying to understand SUID functionality.

So what I try is to create script.sh which modifies let say file a.txt.
The script.sh is owned by specific user, let say test1 and group test1. Also file a.txt is same user and group. Now I do not allow to write for other users to file a.txt, however I set rws------ on script.sh (SUID is set)
File a.txt has permissions rwxr--r--. Now when I execute script.sh as user test2 I got permission error on a.txt.
I understood execution of script.sh is fired from user test2 but as it was run by user test1 who actually has write permisions to a.txt file.
Must be I understand it wrongly. I understood user test2 can't modify a.txt file directly but using script.sh may change accordingly if script.sh requires it.
Are you sure the permission error is on a.txt and not on the script itself?
Best would be for you to post the actual command run and the result you got, in code tags. Also the actual result of the ls -l command on the script and the text file.

If
Code:
-rws------ test1 test1 Sep  7 10:10 script.sh
Then user test2 can't read the file to execute it. It probably needs to be
Code:
-rwsr--r-- test1 test1 Sep  7 10:10 script.sh
## or maybe...I'm fuzzy about this
-rwsr-xr-x test1 test1 Sep  7 10:10 script.sh
As I understand it, SUID is used to grant the permissions of user test1 to the script when executed by some other user. It does not grant access to the script. That must still be given in the normal way.

Last edited by scasey; 09-08-2019 at 05:03 PM.
 
1 members found this post helpful.
Old 09-08-2019, 07:26 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
SUID doesn't work with scripts. A discussion of the problem with possible solutions or alternatives is at https://unix.stackexchange.com/quest...-shell-scripts.
 
2 members found this post helpful.
Old 09-08-2019, 07:53 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Perhaps a more correct thing to allow other users to access a script and support files would be to make them 755 permissions and place them in /usr/bin, /usr/sbin, /usr/local/bin, or /usr/local/sbin.
 
1 members found this post helpful.
Old 09-08-2019, 08:34 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
suid means it is executed as the owner of the file and not the user who executes it

if the user can't execute it.. well
 
1 members found this post helpful.
Old 09-09-2019, 12:52 AM   #6
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by makupl View Post
Now I do not allow to write for other users to file a.txt, however I set rws------ on script.sh (SUID is set)
Which means the shell that executes script.sh has the rights that IT's userID (user1) has. This suid right is NOT inherited by its children, like the (child) program that works on a.txt (you didn't say, but I assume it is an editor).
So only internal (built-in) commands of the shell run as user1.
That's why suid for a script mostly isn't all that useful, the applications that do the actual work have to be suid too (or run through sudo, but then you don't need the suid at all).

Last edited by ehartman; 09-09-2019 at 12:55 AM.
 
1 members found this post helpful.
Old 09-09-2019, 01:25 PM   #7
makupl
LQ Newbie
 
Registered: Sep 2013
Posts: 23

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by ehartman View Post
Which means the shell that executes script.sh has the rights that IT's userID (user1) has. This suid right is NOT inherited by its children, like the (child) program that works on a.txt (you didn't say, but I assume it is an editor).
So only internal (built-in) commands of the shell run as user1.
That's why suid for a script mostly isn't all that useful, the applications that do the actual work have to be suid too (or run through sudo, but then you don't need the suid at all).
Thanks you (and others). It answers my question.
M.
 
  


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
[SOLVED] explanation of "SUID" In detail rajasekhar19489 Linux - Newbie 2 10-21-2010 01:50 AM
Using "sed" - a simple explanation needed midiox Linux - Newbie 2 04-03-2006 06:47 AM
A total explanation of Sharing and Accessing SuSE 9.2 in WIN Xp is needed. HELP ! ! ! bedi-beparwah Linux - Networking 1 03-31-2005 12:45 PM
broad explanation needed stabu Linux - Newbie 1 10-09-2004 06:22 AM
SUID file drops suid bit on append? c_coder Programming 1 03-12-2004 07:59 AM

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

All times are GMT -5. The time now is 10:36 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
Open Source Consulting | Domain Registration