问题原文
原帖链接 · bevacqua · CC BY-SA 3.0
Disclaimer: I'm pretty novice at sysadmin stuff.
I'm trying to set up port forwarding in an AWS EC2 instance, this has to be done in the command-line because I don't want to go in and edit anything, it has to be automatic (it's part of a build process).
sudo echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
Permission denied
The weird thing is I've been (successfully) using sudo for pretty much every command that required su privileges. If I do sudo su before the command (trying it out by hand in an ssh session), then it works.
Reasons behind this? Possible solutions that don't involve sudo su or manual edits?
社区高分解答
原帖链接 · jdh8 · CC BY-SA 3.0
The command sudo echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf is interpreted as that you (nonroot) write the result of sudo echo "net.ipv4.ip_forward = 1" into /etc/sysctl.conf.
Run
sudo -s 'echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf'
or
sudo su -c 'echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf'
to run echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf as root.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
