Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #compilers
  • |
  • #embeddedsystems
  • ...
  • View All >>

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.

A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
Regular Expression Laptop Stickers
$20.00 CAD
Regular Expression Laptop Stickers
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
The Most Confusing Grep Mistakes I've Ever Made
The Most Confusing Grep Mistakes I've Ever Made
Published 2020-11-02
Use The 'tail' Command To Monitor Everything
Use The 'tail' Command To Monitor Everything
Published 2021-04-08
Using A Piece Of Paper As A Display Terminal - ed Vs. vim
Using A Piece Of Paper As A Display Terminal - ed Vs. vim
Published 2020-10-05
An Introduction To Data Science On The Linux Command Line
An Introduction To Data Science On The Linux Command Line
Published 2019-10-16
An Overview of How to Do Everything with Raspberry Pi Cameras
An Overview of How to Do Everything with Raspberry Pi Cameras
Published 2019-05-28
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2023 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use