Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

A question about "sudo" and "su" commands.

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

A question about "sudo" and "su" commands.

#1 Post by hack3rcon »

Hello.
Why with "sudo" command some tasks can't be done? For example:

Code: Select all

$ sudo cat /dev/null > sources.list
bash: sources.list: Permission denied
Thank you.

peter_irich
Posts: 1403
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation
Been thanked: 11 times

Re: A question about "sudo" and "su" commands.

#2 Post by peter_irich »

sudo has no effect to redirection. It is possible to bypass, but I not remember how, I prefer use root with "su -".

Peter.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: A question about "sudo" and "su" commands.

#3 Post by Head_on_a_Stick »

Try

Code: Select all

sudo sh -c 'cat /dev/null > sources.list'
Or with su:

Code: Select all

su -c 'cat /dev/null > sources.list'
deadbang

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Re: A question about "sudo" and "su" commands.

#4 Post by hack3rcon »

peter_irich wrote:sudo has no effect to redirection. It is possible to bypass, but I not remember how, I prefer use root with "su -".

Peter.
Thanks.

theblueplll
Posts: 154
Joined: 2019-04-29 01:17
Been thanked: 2 times

Re: A question about "sudo" and "su" commands.

#5 Post by theblueplll »

Or

Code: Select all

sudo su
hit enter then type your password
and any command under the sun that is supported by your OS will work

Just remember

Code: Select all

exit
when you're finished to log out of being root

AND be careful what you do there is no "you shouldn't do this" warning in LInux when using the terminal LoL

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: A question about "sudo" and "su" commands.

#6 Post by Head_on_a_Stick »

theblueplll wrote:

Code: Select all

sudo su
That won't work properly for Debian buster because PATH won't include the sbin directories (although it will work for the specific example given in the OP). And using both sudo and su together is just silly.

To attain a root shell with the correct PATH & IFS set then use either

Code: Select all

sudo -i
Or

Code: Select all

su -
deadbang

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: A question about "sudo" and "su" commands.

#7 Post by Dai_trying »

Both sudo su and sudo i give me same results on my Buster Xfce installation. But i'm not arguing in favour of using sudo su, just saying...

Code: Select all

dai@Buster:~$ sudo su
[sudo] password for dai: 
root@Buster:/home/dai# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@Buster:/home/dai# exit
exit
dai@Buster:~$ sudo -i
root@Buster:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@Buster:~# exit
logout
dai@Buster:~$ 

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: A question about "sudo" and "su" commands.

#8 Post by GarryRicketson »

And using both sudo and su together is just silly.
Agree, it is pointless, "su" logs you in as root, and "sudo", gives the logged in user root permissions, assuming sudoers ,etc is all set up correctly.
So what is the point of using "sudo", to just use "su", when all one really needed to do is type in "su" in the first place. It just does not make sense at all to me why anyone would think they need to use "sudo", to run the "su" command, where do people get these ideas ?
Just remember

Code: Select all

    exit 
when you're finished to log out of being root
That is the main point and reason for using "sudo", if one uses sudo , they do not need to type "exit", they stop being sudo, after they run the command.
And another thing, while I am at it,
AND be careful what you do there is no "you shouldn't do this" warning in LInux when using the terminal LoL

Code: Select all

man su 
=====

Code: Select all

man sudo
if the admin does not have enough sense and logic, to read the manual and learn the correct options, etc,..they really should not be using either one, and certainly should not be in the sudoers file to start with.
Besides that, the OP could have just used these keywords:

Code: Select all

How to use su and sudo on Debian correctly 
Into their favorite search engine, please at least try to do some searches before asking, there is plenty of good documentation on using su or sudo, all ready written.
The first hit on "sudo" :https://wiki.debian.org/sudo
Another good one: https://www.rootusers.com/the-differenc ... -in-linux/
And there are more, please note, in neither of the above do they say anything about using "sudo su", that is absurd

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: A question about "sudo" and "su" commands.

#9 Post by Head_on_a_Stick »

Dai_trying wrote:Both sudo su and sudo i give me same results on my Buster Xfce installation.
Yes, of course, sudo will set PATH & IFS. Thanks for the correction.
deadbang

theblueplll
Posts: 154
Joined: 2019-04-29 01:17
Been thanked: 2 times

Re: A question about "sudo" and "su" commands.

#10 Post by theblueplll »

Head_on_a_Stick wrote:
theblueplll wrote:

Code: Select all

sudo su
That won't work properly for Debian buster because PATH won't include the sbin directories (although it will work for the specific example given in the OP). And using both sudo and su together is just silly.

To attain a root shell with the correct PATH & IFS set then use either

Code: Select all

sudo -i
Or

Code: Select all

su -
I did not know this.
I had been doing it because I saw it somewhere(I think theres something in the link in your sig about not doing that)I think idk.

Anyway the root account is locked on my machine so

Code: Select all

:~$ su
Password: 
su: Authentication failure
I get that when I try to su.

But I see that

Code: Select all

sudo -i
Gives me a root shell like you said so I guess I'll be using that now if that is the proper command.

Thank you for correcting me.

Post Reply