Ask Ubuntu Asked by Graviton on December 16, 2020
I know you can use su
to switch users within the terminal. As the account I use is non-root (without superuser permissions), it brings up a password prompt for the user I log into.
Is there a way to use su
or something similar to login using a one line command? For example,
su -l USERNAME PASSWORD
Something like this could be used in a bash script for example.
While I wouldn't recommend it (unless the use case explicitly calls for it), you can use something like the following in a shell script:
"echo PASSWORD | sudo -S COMMAND"
Where PASSWORD is the user password, and COMMAND is the command to run at the elevated permissions level.
Note that the -S
option is important, as it redirects input from term to standard input. See Sudo Manual for additional details.
Answered by richbl on December 16, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP