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.

If your logged in as root there should be no need to use sudo.

Something like this should do:

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