When I work on Linux test server (Debian 11) I have root, and want block other users open new session to this server during my work.
Is it possible?
When you are logged in as root, you can create a file named /var/run/nologin (historically /etc/nologin), and this should prevent non root users from logging in. When you are done your work as root, you can then delete that file to resume access to other users.
See the man page for nologin (5):
Name
nologin - prevent unprivileged users from logging into the system
Description
If the file
/etc/nologinexists and is readable,login(1) will allow access only to root. Other users will be shown the contents of this file and their logins will be refused.
On at least some systems this is controlled through PAM with the pam_nologin module. on Debian this module is the first account entry for login and sshd, placed before the inclusion of common_account:
# Disallow non-root logins when /etc/nologin exists. account required pam_nologin.so pam_nologin throughout all its examples. You might want to test with /var/run/nologin as well as /etc/nologin /var/run/nologin did it on FreeBSD. Yes, it's possible. See man sshd_config for information on how to restrict who can authenticate.
You could add the AllowGroups root directive to the sshd config manually, then make the sshd service reload.