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 ...

Get Linux and Unix Shell Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.