Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #269301
| From | <tomas@tuxteam.de> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | sudo echo 1 > /proc/sys/net/ipv4/ip_forward [was: How to run automatically a script as soon root login] |
| Date | 2024-05-13 19:00 +0200 |
| Message-ID | <IDHbQ-d6ym-7@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
[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
Back to linux.debian.user | Previous | Next — Next in thread | Find similar | Unroll thread
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
csiph-web