• sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatica

    From [email protected]@21:1/5 to All on Mon May 13 19:00:02 2024
    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

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZkJFWAAKCRAFyCz1etHa Rm5pAJ9E7Q4pVr+ewaV2KufCphxNNNTT9wCdGBuamTE026A7vv77Uhp2wdCCJJU=
    =ru8b
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Groessler@21:1/5 to [email protected] on Mon May 13 19:30:01 2024
    On 5/13/24 18:52, [email protected] 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Monnier@21:1/5 to All on Mon May 13 19:50:01 2024
    $ 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Stefan Monnier on Mon May 13 20:10:02 2024
    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

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZkJV+QAKCRAFyCz1etHa RqQCAJ0ShlZI5lKKk0E91nPpIgH4O4qcTgCbBlU6bHAWV2e4vUcm+/lkKFSmC/8=
    =sK1w
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Erwan David@21:1/5 to All on Mon May 13 20:40:02 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Erwan David on Tue May 14 06:30:02 2024
    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

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZkLn3wAKCRAFyCz1etHa Rm73AJ46gZ4ZaBYkvEnLXStV30lkbzivCgCfeU9MZ1uaXO9cs8Qdvboa9dDD8sk=
    =2vCb
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Bret Busby on Tue May 14 11:10:01 2024
    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

    -----BEGIN PGP SIGNATURE-----

    iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZkMoGQAKCRAFyCz1etHa RjlFAJoCa3pEKYvPd+vGqO7e+cQFnGiRwQCbBD70SiEOOjv7PcQVJDDZ/zVJT2o=
    =Zax3
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bret Busby@21:1/5 to All on Tue May 14 11:00:01 2024
    Wasn't sudo echo the name of a pop group?

    :)


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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)