LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-22-2021, 06:15 AM   #1
DarkBrainsDecoder
LQ Newbie
 
Registered: Feb 2021
Posts: 6

Rep: Reputation: Disabled
Unhappy 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
 
Old 02-22-2021, 06:18 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you need to read the man page of the tool:
su [options] [username]
but I think you are looking for sudo (not su). And again, see man page about usage.
 
1 members found this post helpful.
Old 02-22-2021, 11:56 AM   #3
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
su username -c "command"

will work to execute a command as the named user and requires knowing the password for that user.

sudo su username -c "command"

will do the same but only requires your password

It may be that the question is "how to switch to a different user (specify the long version of the option)" in which case

su --login username

will give you a clean login environment for that user and still requires knowing that user's
password.

Read the man pages for su and sudo to learn what options are available and what they do.

Last edited by computersavvy; 02-22-2021 at 12:04 PM.
 
1 members found this post helpful.
Old 02-23-2021, 12:40 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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].
 
Old 02-23-2021, 12:21 PM   #5
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by pan64 View Post
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.
 
1 members found this post helpful.
Old 02-23-2021, 01:06 PM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by computersavvy View Post
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).
 
Old 02-23-2021, 04:58 PM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by pan64 View Post
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).
 
Old 02-23-2021, 05:13 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by computersavvy View Post
It may be that the question is "how to switch to a different user (specify the long version of the option)" in which case

su --login username

will give you a clean login environment for that user and still requires knowing that user's
password.
"ssh username@0" does the same thing. Back in more trusting times -- and before it became the Wrong Thing To Do -- so did "telnet 0 username".
 
Old 02-23-2021, 06:30 PM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,793

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Because of less overhead and cleaner logging you should do

sudo -su username
sudo -su username command

rather than

sudo su username
sudo su username -c "command"

and

sudo -iu username
sudo -iu username command

rather than

sudo su - username
sudo su - username -c "command"
(where the traditional "-" works like the GNU "--login")
 
Old 04-11-2021, 12:07 AM   #10
vipulsharma
LQ Newbie
 
Registered: Apr 2021
Posts: 1

Rep: Reputation: Disabled
Arrow The Trick Lies In The Question Itself!

Which "option" needs to be set to "execute a command" as a different user using the "su" command? (long version of the option)

--command
 
Old 10-19-2022, 01:24 PM   #11
lilcanila
LQ Newbie
 
Registered: Oct 2022
Posts: 1

Rep: Reputation: 0
Solving problems

Ok, just first get your credentials on the desktop to know your password (remember the password is invisible on linux console)

then execute:

$su
(tipe your password)

then

#su --help -> here are the su's options and your answer (choose the long one)

u're welcome to the future students.

I know it's not the direct answer but you need to learn how to solve this kind of problems to achieve your goals.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Aboout "with very long lines",how long is very long? yun1st Linux - Newbie 4 07-20-2012 03:38 PM
long long long: Too long for GCC Kenny_Strawn Programming 5 09-18-2010 01:14 AM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
How to convert "unsigned long long" to "char pointer"? novicehacker Linux - Kernel 1 11-20-2006 12:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration