Lab 25.2 the echo method requires you to be root; sudo won’t work.
Hey guys,
There is a note in 25.2 "In the below we are going to use two methods, one involvingsysctl, the other directly echoing values to/proc/sys/kernel/pid_max. Note that theechomethod requires you to be root;sudowon’t work. We’ll leave it to you to figureout why, if you don’t already know!"
The method mentioned is:
$ echo 24000 > /proc/sys/kernel/pid_max # This must be done as root
I can't figure out why. Can someone help?
Comments
-
if you don't do it as root (through su say) you have to do:
sudo sh -c "echo ......pid_max"
it is because you cannot do something like sudo echo "something" > /root/something" because you don't have permission to write something in that directory. echo has to start a new shell to redirect the output to a privileged directory; thus you must start a new shell before you do the echo which is what "sh -c" does
1 -
I get it. in fact, the shell does the redirect, not the 'echo' command even under sudo, and the shell is running under the regular user. Thanks.
0 -
You can try adding the following alias, which passes your environment to the sudo'ed command (simply put), to your .bashrc file: alias sudo='sudo '
However, i doubt it would work for the echo command, but it's quite handy in general, but you can use the print command:
$ sudo printf "%s\n" "24000" > /proc/sys/kernel/pid_max
Works without issues here.Did a quick test using:
sudo printf "%s\n" "24000" > /home/USER/file.stringtest (since i've no interest in changing the maximal amount of PIDs allowed at this time).
Output:
[user@ ~]$ cat file.stringtest
24000
[user@ ~]$As which was expected, it created the file with 24000 written as a string, ending with a newline to emulate echo's default behaviour.
The printf command is usually a bit more flexible than the echo command (in this case you could drop the string and newline option for the command but for general files, it is a better example).0 -
When you have something like the following:
echo "something" > /dir/file
the shell opens first the ">", before executing the command (in a sub-shell).
If you don't have permissions to write to that file, you get the error "...permission denied...".
The above is valid even if you execute the command as "sudo".
Another way, except those already suggested above can be:
echo "something" | sudo tee /dir/file > /dev/null
0 -
That's a relatively simple trick I've never seen and it works. Just to confirm:
c8:/usr/bin>echo hello > hello bash: hello: Permission denied c8:/usr/bin>echo hello | sudo tee hello hello c8:/usr/bin>cat hello hello c8:/usr/bin>ls -l hello -rw-r--r-- 1 root root 6 Apr 9 08:01 hello c8:/usr/bin>
I'm actually kind of surprised "tee" does not open a new shell in the
way echo does. Go figure
I'll ask a couple of experts and strace myself.0
Categories
- All Categories
- 175 LFX Mentorship
- 175 LFX Mentorship: Linux Kernel
- 745 Linux Foundation IT Professional Programs
- 372 Cloud Engineer IT Professional Program
- 168 Advanced Cloud Engineer IT Professional Program
- 73 DevOps IT Professional Program - Discontinued
- 3 DevOps & GitOps IT Professional Program
- 98 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- AI & ML Training
- Blockchain & Decentralized Identity Training
- Cloud & Containers Training
- Cybersecurity Training
- DevOps & Site-Reliability Training
- Linux Kernel Development Training
- Networking Training
- Open Source Best Practice Training
- System Administration Training
- System Engineering Training
- Web & Application Development Training
- 2 LFD103-JP クラス フォーラム
- 4 LFD210-CN Class Forum
- 764 LFD259 Class Forum
- 681 LFS101 Class Forum
- 2 LFS158-JP クラス フォーラム
- 162 LFS207 Class Forum
- 3 LFS207-DE-Klassenforum
- 4 LFS207-JP クラス フォーラム
- 61 LFS241 Class Forum
- 52 LFS242 Class Forum
- 42 LFS243 Class Forum
- 19 LFS244 Class Forum
- 4 LFS250-JP クラス フォーラム
- 166 LFS253 Class Forum
- 19 LFS256 Class Forum
- 1.4K LFS258 Class Forum
- 165 LFS261 Class Forum
- 26 LFS267 Class Forum
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 945 Programming and Development
- 310 Kernel Development
- 617 Software Development
- 977 Software
- 369 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)

