Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-12-2012, 12:30 AM   #1
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
Old 12-12-2012, 12:56 AM   #2
Registered: Aug 2005
Location: Brazil
Distribution: Debian Jessie
Posts: 795

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

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

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

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

# chmod 750 /path/to/


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 09:57 AM
How to run script of another user from root? sikandar Linux - Software 4 09-05-2007 04:42 AM
can run script from my user but not with cron beeblequix Linux - Enterprise 2 04-13-2007 11: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 08:54 AM
Run a script as a different user dtheorem Programming 5 11-05-2003 06:57 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration