33 hours ago
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.
15 hours ago
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.