Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-14 Thread tomas
On Tue, May 14, 2024 at 04:54:26PM +0800, Bret Busby wrote:
> 
> Wasn't sudo echo the name of a pop group?
> 
> :)

If it wasn't it should've been one.

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-14 Thread Bret Busby



Wasn't sudo echo the name of a pop group?

:)



Bret Busby
Armadale
Western Australia
(UTC+0800)
.



Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread tomas
On Mon, May 13, 2024 at 08:37:16PM +0200, Erwan David wrote:
> Le 13/05/2024 à 19:45, Stefan Monnier a écrit :

[...]

> >  % sudo zsh -l
> >  # echo 1 > /proc/sys/net/ipv4/ip_forward
> >  # ^D
> >  logout
> >  %
> > 
> > 🙂
> > 
> > 
> >  Stefan
> > 
> > 
> sudo -i will do the job instead of sudo zsh -l

...provided Stefan's shell in /etc/passwd is set to
zsh, that is :)

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread Erwan David

Le 13/05/2024 à 19:45, Stefan Monnier a écrit :

$ su -
Password:
# echo 1 > /proc/sys/net/ipv4/ip_forward
# ^D
logout
$

I don't need no stinkin' sudo :-)

And if you only have `sudo`, but not the root password, of course:

 % sudo zsh -l
 # echo 1 > /proc/sys/net/ipv4/ip_forward
 # ^D
 logout
 %

🙂


 Stefan



sudo -i will do the job instead of sudo zsh -l



Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread tomas
On Mon, May 13, 2024 at 01:45:40PM -0400, Stefan Monnier wrote:
> > $ su -
> > Password:
> > # echo 1 > /proc/sys/net/ipv4/ip_forward
> > # ^D
> > logout
> > $
> >
> > I don't need no stinkin' sudo :-)
> 
> And if you only have `sudo`, but not the root password, of course:
> 
> % sudo zsh -l
> # echo 1 > /proc/sys/net/ipv4/ip_forward
> # ^D
> logout
> %

Or just "sudo -s", which will invoke "your" favourite shell. Or "sudo -i",
which will do roughly the same (-s looks first at $SHELL, then at passwd,
-i looks at passwd and invokes a login shell).

> 🙂

I always forget how my fave shell is spelt ;-)

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread Stefan Monnier
> $ su -
> Password:
> # echo 1 > /proc/sys/net/ipv4/ip_forward
> # ^D
> logout
> $
>
> I don't need no stinkin' sudo :-)

And if you only have `sudo`, but not the root password, of course:

% sudo zsh -l
# echo 1 > /proc/sys/net/ipv4/ip_forward
# ^D
logout
%

🙂


Stefan



Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread Christian Groessler

On 5/13/24 18:52, to...@tuxteam.de wrote:


Now share your ideas :-)



$ su -
Password:
# echo 1 > /proc/sys/net/ipv4/ip_forward
# ^D
logout
$


I don't need no stinkin' sudo :-)

regards,
chris



sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]

2024-05-13 Thread tomas
Since this happens so often, I'm trying to offer a recap.

As others have noted, the above

  sudo echo 1 > /proc/sys/net/ipv4/ip_forward

won't work, since it runs echo under sudo, but the file opening
(that pesky ">") happens in your shell, which is probably running
unprivileged (otherwise, what do you need the sudo for, anyway?)

Others have rightfully noticed that, in this case, sysctl possibly
is the more appropriate tool for the job.

Barring that -- what is to do?

One solution put forward was to wrap a whole shell in the sudo:

  sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Of course, you can (gasp!) wrap a whole xterm which invokes a
shell (why not go the full thing and wrap LibreOffice Calc? It
surely has a shell escape hidden somewhere ;-)

Another solution is to find a program which would be willing
to open a named file for you and sudo that one.

A common choice would be tee (which in this case has the side
effect of dumping the desired output *also* to stdout:

  echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

(also outputs 1 to stdout). Less common, but my personal favourite
is dd, which is free of that side effect (it's harmless enough
when it's just an "1", but if longer data is involved...):

  echo 1 | sudo dd of=/proc/sys/net/ipv4/ip_forward

(note that dd's default if is stdin).

Now share your ideas :-)

Cheers
-- 
t


signature.asc
Description: PGP signature