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.

pankaj_ar
  • 757
  • 2
  • 10
  • 33

2 Answers2

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"
Olivier Dulac
  • 3,695
  • 16
  • 31
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
Nachiket Kate
  • 8,473
  • 2
  • 27
  • 45