O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

27.4. access.deny

To keep users from logging into the system when you are carrying out live updates, you can use the /etc/nologin method, available on most systems. When you create a file called nologin in /etc usually with the touch command, no users apart from root are allowed to log in.

If your system is one of the few that do not support the nologin method, all is not lost – you can create this function yourself. Here’s what to do.

Put the following code in your /etc/profile.

if [ -f /etc/nologin ]; then 
  if [ $LOGNAME != "root" ]; then 
    echo "Sorry $LOGNAME the system is unavailable at the moment" 
    exit 1 
  fi 
fi

Now, when you want to stop all users logging in, apart from root that is, use the touch command to create a nologin file in /etc ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required