1

New to Linux attempting an exercise to overwrite /proc/sys/fs/file-max

sudo sh -c 300000 > file-max returns bash: file-max: Permission denied. Do I actually have to be root to do this? the user account I'm using has been added to the sudo user group.

I saw variations of this question posted mostly attempting to modify different folders and the above command was the recommendation to alleviate the issue, but is the /proc directory different?

Note: using most recent Kali Linux release.

DopeGhoti
  • 76,081
Tor
  • 11
  • 1
    You should not comment on your own question (except for responses to other comments) but edit it. – Hauke Laging Jan 08 '18 at 22:20
  • @Tor Where did you see that recommended? That command would try to start a shell to run a command called 300000, which probably isn't going to be found (even if the redirection succeeds) – ilkkachu Jan 08 '18 at 22:24
  • Also: https://unix.stackexchange.com/questions/6713/sudo-permission-denied-but-su-grants-permission – ilkkachu Jan 08 '18 at 22:24

3 Answers3

3

Your proposed command is nonsensical. sudo sh -c 300000 > file-max will attempt to have a superuser shell run the command 300000 and redirect the output into a file called file-max in the nonsuperuser shell's current working directory.

You are probably instead looking to do something like:

sudo sh -c 'echo 300000 > /proc/fs/file-max'

That said, writing directly to /proc is a somewhat hacky way to alter these properties. A more "respectable" way to effect this change would be:

sudo sysctl -w fs.file-max=300000
DopeGhoti
  • 76,081
1

The problem there is that /proc/file-max is being overwritten as your user and not root.

Do:

echo 300000 | sudo tee /proc/sys/fs/file-max

or:

sudo sysctl -w fs.file-max=300000

You must restart your network for the change to take effect. The command to manually restart the network is the following:

sudo service networking restart

You should also add fs.file-max=300000 to /etc/sysctl.conf for the setting to survive a reboot of the server.

echo "fs.file-max=300000" | sudo tee -a /etc/sysctl.conf
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • 1
    Thanks, I knew that had something to do with it but I wasn't entirely certain what order to use to utilize tee! Appreciate the help. – Tor Jan 08 '18 at 22:29
1

The redirection is executed before sudo thus sudo cannot elevate the permissions of the redirection. You need a shell with root permissions to do this:

sudo bash -c 'echo 300000 >/proc/sys/fs/file-max'
Hauke Laging
  • 90,279