Intro To 'false' Command In Linux
2023-05-21 - By Robert Elder
I use the 'false' command which does absolutely nothing and then exits unsuccessfully:
false
The 'false' command can be built into the shell or it can exist as a regular executable:
type -a false
false is a shell builtin
false is /usr/bin/false
false is /bin/false
Return Code 1 == 'Failure'
Whenever you run the 'false' command, it will exit with an unsuccessful return code:
false
You can verify this by echoing the dollar sign question mark variable and then observing the value of 1 which indicates an unsuccessful program exit:
echo $?
1
Use Case Of 'false' Command
An example application of the 'false' command is to deny certain users the ability to access a shell environment.
For example, on my machine the postgres user is configured to spawn the '/bin/bash' shell environment upon login:
cat /etc/passwd | grep postgres
postgres:x:126:133:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
Whenever I use sudo to become the 'postgres' user:
sudo -u postgres -i
this will work normally and run the '/bin/bash' shell as indicated in '/etc/passwd'.
However, the 'tomcat' user is configured to launch the 'false' command as its login shell:
cat /etc/passwd | grep tomcat
tomcat:x:1001:1001::/opt/tomcat:/bin/false
This fails immediately and prevents access to any form of login shell:
sudo -u tomcat -i
echo $?
1
This is because the 'false' command simply exits immediately with an error code.
And that's why the 'false' command is my favourite Linux command.
![]() Intro To 'stty' Command In Linux
Published 2023-10-04 |
![]() $1.00 CAD |
![]() Intro To 'nproc' Command In Linux
Published 2023-07-15 |
![]() Intro To 'comm' Command In Linux
Published 2023-09-06 |
![]() How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
![]() A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
![]() A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
![]() Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|