Server maintenance is an essential process that ensures stable and secure operation. However, before beginning such tasks, it’s important to organize the process properly: restrict access to the system, notify current users, and gracefully terminate their sessions. In this article, we’ll discuss how to use standard Linux utilities such as wall , pkill , and write to notify users about upcoming actions, terminate their sessions, and safely carry out maintenance tasks.
Restricting Access
To start, create an empty file /etc/nologin . This will restrict access to the system, allowing only the root user to log in. All other users will be unable to authenticate via SSH.
However, before shutting down access, it's essential to inform users who are currently logged into the system. To do this, we can utilize the wall tool.
What is wall?
The wall command is a powerful utility in the command-line interface, designed to broadcast messages to all active users logged into the system. These messages are delivered directly to the terminal windows of every connected user, ensuring instant visibility.You can deliver a message by executing the following command:
wall "The server will be unavailable for maintenance starting at 12:00"
Once executed, every logged-in user will see the message on their screen, regardless of what they’re doing. Additionally, wall can be used to send messages to specific groups of users.
Terminating User Sessions
At the scheduled time, you can forcefully terminate all active user sessions, except for root , with the following command:
pkill -9 -u $(who | awk '{print $1}' | grep -v root | head -1)
The server is now free for maintenance tasks. After completing the maintenance, don’t forget to delete the /etc/nologin file to restore access for other users.
Alternatives to wall
If the wall utility is not available for any reason, you can explore alternative ways to notify users:
- Send a message to an individual user:
echo "Message for the user" | write username
Replace username with the name of the intended user.
- Send a message to a specific terminal:
echo "Maintenance will start in 5 minutes" > /dev/pts/1
This method is useful if you know the terminal session ID.
The write utility is another way to send a message to a specific user with an active session on the system.
If you need to alert all users but wall is unavailable, you can write a small script to iterate through all active users and send them notifications using echo .
Now, you’re ready to perform server maintenance with minimal inconvenience to your users!
FAQ: Frequently Asked Questions
- What if the wall utility is missing on the server?
You can use alternative methods, such as write for individual users or redirecting messages to terminals via /dev/pts/* . Additionally, you can create a simple script to notify all active users. - Should I delete the /etc/nologin file after maintenance?
Yes, deleting this file is necessary to restore access for regular users. Otherwise, they won’t be able to log into the system. - How can I find out who is currently logged into the server?
Run the who command. It will show a list of all active users along with their associated terminals. - Can users ignore messages from wall ?
No, messages from wall will be displayed for all logged-in users. The only exception is if a user redirects their terminal output to a file, which is rare. - How can I send messages to a specific group of users?
You can filter users with grep or write a script to send messages only to those meeting certain criteria. For instance, you can send messages exclusively to users connected via SSH.
Serverspace and Linux Knowledge Base
In our Knowledge Base you will find many articles and tutorials on Unix systems, Windows and many other topics such as: Creating a digital signature with GPG; GPG error troubleshooting; Link aggregation on Linux;