0

Is there any way to execute the 'su(switch user)' command with the password given in the same command itself like su root -p "password"

Aparna
  • 1

1 Answers1

2

I am going to answer this by saying that you really do not want to do it this way, and the way su works is probably by design so that you don't do it like this.

Entering your password in cleartext to be preserved in your shell's history for anyone to see who can get read rights into your folder is really bad security practice.

Kurankat
  • 1,193
  • As I am going to code, like getting a password from the UI and passing it to my specific function where I will use this 'su' command with a password . so I need such command or any other way to accomplish this task without prompting for a password. – Aparna Aug 20 '20 at 10:28
  • If you want to perform root functions, you should consider running your entire script as root instead. – Artur Meinild Aug 20 '20 at 11:05
  • @Aparna that is a design flaw in your code. What you should do is create a file on disk with the contents you want to process and have the system act when it sees that file appear. No need for a password if you do it like that. – Rinzwind Aug 20 '20 at 11:40