0

Assume I am user A(not root user) and I want to run a c-shell script which will execute command in User B(password for B is known to me) and will use the result of that command here.

How can I run a command in User-B.

sudo -u username command1

Above command may prompt for password but I want this to be done in script only.

Thanks for all your suggestions.

2 Answers 2

1

you could use a ssh key to allow your user A to log in as user B using user A's private key (and with user A's public key in ~B/.ssh/authorised_keys)

then you simply execute the script as B with:

ssh B@localhost "/path/to/script  and maybe some arguments here"
Sign up to request clarification or add additional context in comments.

Comments

0

you have following options,

  1. run your command with root so that su - username wont prompt for password
  2. create passordless login for user like passwordless ssh,remove password for user etc. and then run your command

for getting output here to work,

  1. write it in a file and access it in code
  2. store it in a variable and access it in code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.