script to su with password in script without root

I have scripted a process that involves updating symbolic links on files located on 3 different machines. On those machines exists 4 users each, who each need to have these links updated.

Using su, is there a way to pass the password argument to the command on a single line, without invoking sudo as the users will not have admin rights?

My only alternative solution at this point is to ssh around, however I would like to be able to do this without hardcoding in a bunch of hosts/ips.

1 Answer

You can pipe the password to su like this:

echo pa$$w0rd | su -c whoami user_1 
6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like