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
  • @GeorgeUdosen No,I want to use su(switch user) command and not sudo. – Aparna Aug 20 '20 at 10:49
  • @Aparna Most of the times you can't even use `su`. See [Why does su fail with “authentication error”?](https://askubuntu.com/questions/446570). – Kulfy Aug 20 '20 at 10:55
  • @Kulfy Yes. Thank you. I think in the root account enabled(its not recommended but in case if it is enabled) machine it won't be a problem. I need to use su command where it is supported and wont fail. I just dont need the prompt of asking password. – Aparna Aug 20 '20 at 11:10
  • As per all the suggestions given, concluded that it's better to directly log in as root user itself if it badly needs than switching users from local to the Root account. – Aparna Aug 20 '20 at 14:00

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,153
  • 5
  • 14
  • 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