Which option needs to be set to execute a command as a different user using the "su" command? (long version of the option)
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.
Which option needs to be set to execute a command as a different user using the "su" command? (long version of the option)
I am new to Linux and the question has also asked to provide the long option as the answer. This is a question from the HTB Academy free box, while solving I have tried many options like
Quote:
-user
-username
but all the answers are getting rejected. Where am I making the mistake?
I know that su takes by default the root if not defined but when I need to define I need to provide the user's name. Following this I Have tried but with no success
Last edited by DarkBrainsDecoder; 02-22-2021 at 06:18 AM.
Reason: I described as to why I have given such answers
just a comment: su and sudo should not be used together.
You need to know both and [obviously] need to select the proper one [in every case].
Should not possibly, but in some cases it may be necessary.
If I am doing a major reconfig of a system where I need to use sudo on many different consecutive commands and the root password has never been set, then rather that adding a root password and using su I would prefer to use sudo su for security reasons. I suspect others do the same at times.
Also if a user comes up to me with a problem I can use the "sudo su username -" to get directly into the users environment and mimic his situation to identify a fix without ever needing to know his password. Again, a security consideration.
While I would not encourage that practice in most cases it can be advantageous.
All use of sudo is routinely logged, as is use of su, so I don't really see a big problem there.
Should not possibly, but in some cases it may be necessary.
I don't think so. I would rather say: a properly configured sudoers file is sufficient.
I can't see any security reason or any advantage to do that (except the incorrect sudoers file or laziness).
Code:
sudo su username -
# is most probably identical to
sudo -u username /bin/bash -l
# or something similar
no, it is not a big problem, you are right. Bad practice (and probably a security hole too).
I don't think so. I would rather say: a properly configured sudoers file is sufficient.
Except when needing to do a lot of commands as root in a single session on a system that has no root password assigned, or for which you have sudo permissions but not the root password, you are probably correct.
In that situation entering "sudo su" once then the rest of the commands while omitting the sudo is much more keystroke efficient (and easier on the carpal tunnel tendons).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.