Link to home
Create AccountLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

sudo su

hi,
my super user is crm and password is say pwd

sudo crm and sudo su means same or different

what is passwd comand, cut c ommand?
please advise
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of gudii9

ASKER

https://fossbytes.com/sudo-su-difference-linux/
That’s why su also stands for substitute user or switch user. Simply type su followed by the user account name, e.g., sudo fossbytes, and you’ll enter the password for fossbytes. After completing the job, you can exit the root shell by typing exit. Overall, su basically starts another shell instance with the privileges of the intended user.
i logged in as abc_user by giving abc_password
when i did
pwd
it said
/home/abc_user
not i did
su def_user
password:def_password
now i did pwd
it still shows
/home/abc_user
i thought it should have shown as below

/home/def_user
please advise
if you want to switch user and initialize, you have to add the -
su - def_user
without the - the user is simply switched to the new user, while remaining where they were prior.

it is better to use sudo instead of su as su requires the knowledge of the root password. while sudo through configuration of /etc/sudoers (using visudo) and provides a granular control of what elevated commands a user can run.
once you provide the root password to a user to run su -, the user can do anything and everything on the system

Think of it this way, a building manager gets a painting crew to repaint some offices. granting this crew the master key (SU root password) or the other option is to provide them a subset key (sudo) with access to the locations where the paint should be applied.

sudo -i equal to su -
sudo -s equivalent to su
Avatar of gudii9

ASKER

what is difference between -i and -s
Avatar of gudii9

ASKER

all of sudden if forgot and want to know which used i am on what command i have to us
whoami
??
Avatar of gudii9

ASKER

whoami shows def_user though

how - can make so much difference?
Avatar of gudii9

ASKER

when i try to switch back to abc_user by giving
su -abc_user
above did not work
if i give
su - abc_user
i am getting
id: cannot find name for group ID 501
is unix is space sensitive also apart from case sensitivity?
Avatar of gudii9

ASKER

how to love unix inspite of all the challenges it gives with syntax and space and case and small nitty gritty things
when you run sudo or su, you elevate your rights, similar to what happens on windows if you runas /user:somenewuser cmd
in the windows environment a new command window pops up with somenewuser reflected in the heading .....

sudo -i means elevate to root as though it is a new connection. in this case pwd will reflect /root and whoami will report root.
sudo -s means elevate to root. in this case pwd will reflect the path where you were prior to running this comamnd. whoami will report that you are now root.
to switch to another user
sudo -i -u newuser pwd /home/newuser whoami newuser
sudo -s -u newuser pwd same place you were when you ran the command. whoami newuser.

commands available to you in:
man sudo
it describes the options and their meaning.
when you elevate from usera to userb, you simply exit and you return back to be usera.
you seem to be chaining usera to userb to usera?
Avatar of gudii9

ASKER


sudo -i means elevate to root as though it is a new connection. in this case pwd will reflect /root and whoami will report root.
sudo -s means elevate to root. in this case pwd will reflect the path where you were prior to running this comamnd. whoami will report that you are now root.
to switch to another user
sudo -i -u newuser pwd /home/newuser whoami newuser
sudo -s -u newuser pwd same place you were when you ran the command. whoami newuser.

su -i

su -s

when above two used

-s means remain same path eventhough elevated
-i shows new elevated path



su ie switch user is used when ? i think i am kind of clear on sudo now
Avatar of gudii9

ASKER

if i just want to swatch from def_user to abc_user how i do it?
Please make a complete scenario.
if you start with dev_user, and want to end up being abc_user as though you just logged in as that user: su - abc_user.

you are all over the place, and I am having difficulty keeping up with what it is you are trying to address.

IT IS BETTER TO USE sudo since this way you do not have to know the passwords of the other users. it only requires you to know your own password and have the requisite rights assigned/delegated to you to run the command.
Avatar of gudii9

ASKER

su - abc_user.

giving below error
id: cannot find name for group ID 501

how to resolve that and why i get that?
it means that abc_user has a group membership 501 that does not exist in /etc/groups
id abc_user
groupadd -g 501 somegroupname