Saturday, April 27, 2024
97
rated 0 times [  97] [ 0]  / answers: 1 / hits: 327724  / 1 Year ago, sun, january 15, 2023, 6:31:42

I know I can become root (super user) via the su command but I have to authorize it after entering the commands. Is there a way I can become root and authorize (with password) in one line


More From » command-line

 Answers
1

Well, the only thing I can think of is



echo 'password' | sudo -S command


The -S flag makes sudo read the password from the standard input. As explained in man sudo:




-S, --stdin



Write the prompt to the standard error and read the password from the standard input
instead of using the terminal device. The password must be followed by a newline character.




So, to run ls with sudo privileges, you would do



echo 'password' | sudo -S ls


Note that this will produce an error if your sudo access token is active, if you don't need to enter your password because you've already done so recently. To get around that, you could use -k to reset the access token:



echo 'password' | sudo -kS ls


I don't know of any way of getting you into an actual root shell (like su or sudo -i) do. This might be enough for what you need though.


[#25081] Monday, January 16, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itagde

Total Points: 241
Total Questions: 113
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
itagde questions
Thu, Jun 10, 21, 21:24, 3 Years ago
Sat, Aug 13, 22, 22:41, 2 Years ago
Thu, May 20, 21, 11:52, 3 Years ago
Tue, Aug 23, 22, 06:19, 2 Years ago
;