Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #269301 > unrolled thread

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

Started by<tomas@tuxteam.de>
First post2024-05-13 19:00 +0200
Last post2024-05-14 11:10 +0200
Articles 8 — 5 participants

Back to article view | Back to linux.debian.user


Contents

  sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] <tomas@tuxteam.de> - 2024-05-13 19:00 +0200
    Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] Christian Groessler <chris@groessler.org> - 2024-05-13 19:30 +0200
      Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login] Stefan Monnier <monnier@iro.umontreal.ca> - 2024-05-13 19:50 +0200
        Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] <tomas@tuxteam.de> - 2024-05-13 20:10 +0200
        Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] Erwan David <erwan@rail.eu.org> - 2024-05-13 20:40 +0200
          Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] <tomas@tuxteam.de> - 2024-05-14 06:30 +0200
            Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] Bret Busby <bret@busby.net> - 2024-05-14 11:00 +0200
              Re: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run  automatically a script as soon root login] <tomas@tuxteam.de> - 2024-05-14 11:10 +0200

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

From<tomas@tuxteam.de>
Date2024-05-13 19:00 +0200
Subjectsudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]
Message-ID<IDHbQ-d6ym-7@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [next] | [standalone]


#269304

FromChristian Groessler <chris@groessler.org>
Date2024-05-13 19:30 +0200
Message-ID<IDHER-d70C-1@gated-at.bofh.it>
In reply to#269301
On 5/13/24 18:52, tomas@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

[toc] | [prev] | [next] | [standalone]


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

FromStefan Monnier <monnier@iro.umontreal.ca>
Date2024-05-13 19:50 +0200
SubjectRe: sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login]
Message-ID<IDHYd-d7cC-1@gated-at.bofh.it>
In reply to#269304
> $ 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

[toc] | [prev] | [next] | [standalone]


#269306

From<tomas@tuxteam.de>
Date2024-05-13 20:10 +0200
Message-ID<IDIhA-d7yY-33@gated-at.bofh.it>
In reply to#269305

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [next] | [standalone]


#269307

FromErwan David <erwan@rail.eu.org>
Date2024-05-13 20:40 +0200
Message-ID<IDIKC-d7Jl-7@gated-at.bofh.it>
In reply to#269305
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

[toc] | [prev] | [next] | [standalone]


#269316

From<tomas@tuxteam.de>
Date2024-05-14 06:30 +0200
Message-ID<IDRXA-ddpw-1@gated-at.bofh.it>
In reply to#269307

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [next] | [standalone]


#269320

FromBret Busby <bret@busby.net>
Date2024-05-14 11:00 +0200
Message-ID<IDWaR-dfLT-1@gated-at.bofh.it>
In reply to#269316
Wasn't sudo echo the name of a pop group?

:)


....
Bret Busby
Armadale
Western Australia
(UTC+0800)
.................

[toc] | [prev] | [next] | [standalone]


#269321

From<tomas@tuxteam.de>
Date2024-05-14 11:10 +0200
Message-ID<IDWkx-dg4D-5@gated-at.bofh.it>
In reply to#269320

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web