LinuxQuestions.org
Review your favorite Linux distribution.
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 12-11-2012, 11:30 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
su to another user to run script


I have a script ( the name is /tmp/script1) , the content is simple , just copy a file to another directory .

Now I would like every user will change to a specific user ( eg. userA ) before run this script so that the script will be run by userA , that mean I want only userA run this script , I tried make the below change , but it do not work , can advise what can I do ? thanks

$vi newscript
su - userA
/tmp/script1
 
Old 12-11-2012, 11:56 PM   #2
lucmove
Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Jessie
Posts: 755

Rep: Reputation: 73
Create a group, for example "accounting".

Add whatever users you want to the "accounting" group. Example code:

Code:
# for i in $(cat accounting_users.txt); do
  usermod -G accounting $i
  done
Change ownership of the script so it belongs to that group:

Code:
# chgrp accounting /path/to/script.sh
chmod the file so that only users from that group can run it:

Code:
# chmod 750 /path/to/script.sh
 
  


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
Run a script as any user Hi_This_is_Dev Linux - General 5 09-26-2010 08:57 AM
How to run script of another user from root? sikandar Linux - Software 4 09-05-2007 03:42 AM
can run script from my user but not with cron beeblequix Linux - Enterprise 2 04-13-2007 10:22 AM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM
Run a script as a different user dtheorem Programming 5 11-05-2003 05:57 PM


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