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

New to Debian (Or Linux in general)? Ask your questions here!

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

Postby hack3rcon » 2019-07-06 06:18

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.
hack3rcon
 
Posts: 297
Joined: 2015-02-16 09:54

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

Postby peter_irich » 2019-07-06 08:34

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

Peter.
peter_irich
 
Posts: 1257
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

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

Postby Head_on_a_Stick » 2019-07-06 08:40

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'
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10607
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby hack3rcon » 2019-07-06 08:42

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.
hack3rcon
 
Posts: 297
Joined: 2015-02-16 09:54

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

Postby theblueplll » 2019-07-06 18:51

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
theblueplll
 
Posts: 154
Joined: 2019-04-29 01:17

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

Postby Head_on_a_Stick » 2019-07-06 19:12

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 -
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10607
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Dai_trying » 2019-07-06 22:35

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:~$
Dai_trying
 
Posts: 791
Joined: 2016-01-07 12:25

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

Postby GarryRicketson » 2019-07-06 23:36

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-difference-between-su-and-sudo-commands-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
GarryRicketson
 
Posts: 5877
Joined: 2015-01-20 22:16
Location: Durango, Mexico

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

Postby Head_on_a_Stick » 2019-07-07 07:41

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.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10607
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby theblueplll » 2019-07-08 15:12

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.
theblueplll
 
Posts: 154
Joined: 2019-04-29 01:17


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable