How to sudo to multiple users?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sudo to multiple users?
# 1  
Old 10-12-2010
How to sudo to multiple users?

Hi all,

I have to create SSH public key for multiple users.
Iam creating a script in which, through root, I have to switch to multiple accounts to create SSH keys and then transfer it to the respective servers.
First I tried with single user id and everything worked fine.

When I try to sudo from root to different user id, it just going to to command prompt.
I have to maually exit from command prompt to execut the next steps in the script.

When the script execute the follwoing...
sudo [-su] user1

The control goes too...
~/home/user1>

So how can I avoid this manual intervention, so that I can execute the ssh-keygen for multiple users from single script.

Thanks in advance.
# 2  
Old 10-12-2010
If your logged in as root there should be no need to use sudo.

Something like this should do:

Code:
 for user in userA userB userC
do
     su - $user "-c /usr/bin/ssh-keygen"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to check sudo access of other users?

Hi, I always use "sudo -U user -l" as root and it gives me list of sudo access, that person have. But on one Solaris server, I can't run it. recently only I installed latest patchset on this server. Not sure, if that changed something on this. However, sudo package is showing old one. # id -a... (1 Reply)
Discussion started by: ron323232
1 Replies

2. Red Hat

How to disable sudo -i in sudoers file for users?

All, I need to disable "sudo -i" and "su - " for all servers in our environment, We want to make sure no one run commands or delete files across environment using switching to root account. can you guys please lets me know if this is achievable. Thanks and Regards shekar (2 Replies)
Discussion started by: shekar777
2 Replies

3. Shell Programming and Scripting

Create multiple users with individual passwords to users

hi, i am new to shell scripts i write a shell script to create multiple users but i need to give passwords to that users while creating users, command to write this script (1 Reply)
Discussion started by: DONFOX
1 Replies

4. UNIX for Dummies Questions & Answers

Pop the users one by one in sudo cat /etc/security/user

Hi Everyone, When I runthe query in ssh shell sudo cat /etc/security/user , I see half of the users cut down from the display screen. what I want to do is using the somthing like "pop" that when I hit the enter key every time the screen should move to the next user? does some one has any idea how... (4 Replies)
Discussion started by: starter2011
4 Replies

5. Shell Programming and Scripting

ldapsearch - extract 'sudo su' users with awk or sed.

Hello all, Hope you all are doing good :). First of all, I apologize for my bad English I want to get list of all user that have 'sudoCommand: ALL' I've tried different sed and awk combinations without success :wall: the command for extracting the OU for sudo is: ldapsearch -x... (4 Replies)
Discussion started by: corky
4 Replies

6. UNIX for Advanced & Expert Users

How can I get sudo -u <username> to load that users profile on HP-UX

I am running a serverapplication on a HP-UX machine where I need to handle some of the commands as a specified user called "druser". When I log on as this user with the command; sudo -u druser -sit starts an instance of the shell as that user. However, it doesn't load that users .profile from... (1 Reply)
Discussion started by: ukiome
1 Replies

7. Solaris

sudo for users

Hello gurus, Is there a flag or switch that you can added to sudoers file to always have users type 'sudo' prior to running a command? (5 Replies)
Discussion started by: em23
5 Replies

8. UNIX for Dummies Questions & Answers

Is there a way to find users who have sudo permissions for non root?

I want to check if in a host a set of persons have sudo access or not and I dont have root access to the host. (1 Reply)
Discussion started by: pristine
1 Replies

9. Linux

Enable sudo for Win AD users authenticated with Linux samba winbind service

Hi everyone, I wonder if anyone ever came across the idea of unifying AD and Linux user accounts We have a Linux machine with 'samba' 'winbind' service configured to let Windows AD users to logon locally using their AD accounts and passwords. I can use 'su' to get to the local user privilege... (0 Replies)
Discussion started by: will_mike
0 Replies

10. UNIX for Dummies Questions & Answers

Can I export the users environment using sudo?

I want the user to be able to commands as another user.. but when they do that.. I need them to have the environment variables of the other user. is this possible with sudo? sudo -H -u user env 'env' is giving me the environment of the current user, not the user I want to run commands as. ... (1 Reply)
Discussion started by: julesdiane
1 Replies
Login or Register to Ask a Question