[SOLVED] fail to execute "echo 'my password' | sudo -S su" in command line
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
fail to execute "echo 'my password' | sudo -S su" in command line
I tried to run the command
echo 'my password' | sudo -S su
hopefully it can automatically goes into a child process as root,
however the command executes with no error but exit the child process
and back to my existing user privilege.
How can I remain at the child process as 'root' without 'exit'ing from the
process.
hopefully it can automatically goes into a child process as root,
however the command executes with no error but exit the child process
and back to my existing user privilege.
How can I remain at the child process as 'root' without 'exit'ing from the
process.
You could use NOPASSWD flag in sudoers:
Code:
username ALL=(ALL) NOPASSWD: ALL
Then, you can simply run the sudo without specifying the password.
Hopefully this is a trusted user; otherwise anything like this is dangerous.
Another option is to only allow certain commands; for example:
Code:
username ALL=(ALL) NOPASSWD: /full/path/command
This will only allow "username" to run "/full/path/command" with sudo without specifying password.
Adding your name to the file does not mean you can just run all commands, it means you can use sudo before commands to indicate you wish to run them with root privileges using no password.
sudo is not intended to be used to login as root, but to grant you root privileges for one command.
For instance, editing /etc/profile. This file is owned by root and does not have write privileges for other users. Therefore to change it you would need root privileges. To do that you would use the sudo command prefix as part of the call to edit the file:
For instance, editing /etc/profile. This file is owned by root and does not have write privileges for other users. Therefore to change it you would need root privileges. [/code]
Close.
The program sudoedit will invoke your favorite editor but run as a normal user and work from a temporary copy of the file. Only after the temporary file is saved and the editor exited will it then replace the original file. That's much safer.
I tried command 'su',
it prompts for password, but this password is different from my username password, and I am not sure what it is,
I tried with guess it could be 'toor' but failed to authentical.
I merely want to run commands with root privileges without having to key in password at every session,
if cannot be done, then I would like to run a simple script to automatically enter the sudo password
Please look at the manual page for the su command. The full name of it is "Switch User". The default user to switch to is root.
You would not use the sudo command to perform the su command. You would just type su and then after that you would be asked for the root password. After successful entry of the root password, your terminal session would then be logged in as root.
Sudo allows you to USE root privileges for the duration of the command you are entering. One exception to this is that you do not use the sudo command modifier for the default su command.
I merely want to run commands with root privileges without having to key in password at every session,
if cannot be done, then I would like to run a simple script to automatically enter the sudo password
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.