How to allow nologin users to log in on Linux

I have summarized it because I made it possible to log in a nologin user on Linux and verified to change the login user to a nologin user.

Verification environment

Verification content

1. By default, the www-data user is set to nologin, so verify with this user

$ cat /etc/passwd | grep www-data
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

2. The / var / www directory does not exist, so create it

$ sudo mkdir -p /var/www
$ sudo chown www-data:www-data /var/www
$ ls -alF /var/www
total 8
drwxr-xr-x  2 www-data www-data 4096 Nov  7 05:34 ./
drwxr-xr-x 14 root     root     4096 Nov  7 05:34 ../

3. Log in to the nologin user without changing the settings

$ sudo su - www-data --shell=/bin/bash

4. Set the www-data user created by default to log in

###Confirm that you cannot log in
$ sudo su - www-data
This account is currently not available.

###Set to log in
$ sudo usermod -s /bin/bash www-data
$ cat /etc/passwd | grep www-data
www-data:x:33:33:www-data:/var/www:/bin/bash

5. Change settings from logged-in user to nologin user

###Set to prevent login
$ sudo usermod -s /usr/sbin/nologin www-data
$  cat /etc/passwd | grep www-data
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

###Confirm that you cannot log in
$ sudo su - www-data
This account is currently not available.

reference

-Makaasotekku

Recommended Posts

How to allow nologin users to log in on Linux
How to install VMware-Tools on Linux
How to log in to Docker + NGINX
How to install aws-session-manager-plugin on Manajro Linux
How to update php on Amazon linux 2
How to display emoji on Manjaro Linux
How to install packages on Alpine Linux
How to install Anisble on Amazon Linux 2
How to update security on CentOS Linux 8
How to install php7.4 on Linux (Ubuntu)
How to find large files on Linux
How to write regular expression patterns in Linux
How to install Camunda Modeler on Manjaro Linux
I want to log file I / O on Linux
How to build Java environment on Ubuntu (Linux)
How to use C216 Audio Controller on Arch Linux
A memorandum on how to use keras.preprocessing.image in Keras
[AWS EC2] How to install Maven on Amazon Linux 2
How to install git on Linux such as EC2
[Tips] How to use iPhone as webcam on Linux
How to build a Python environment on amazon linux 2
[Linux] How to put your IP in a variable
[AWS] How to expand disk space on Amazon linux
How to develop in Python
A memo on how to easily prepare a Linux exercise environment
How to use linux commands in Visual Studio Code terminal
How to use VS Code in venv environment on windows
Linux: How to recover if'grub_file_filters' not found in grub rescue
[For beginners] How to use for statements on Linux (variables, etc.)
A note on how to load a virtual environment in PyCharm
How to get Instruction Pointer (= program counter) in Linux kernel
Notes on how to use marshmallow in the schema library
How to create an ISO file (CD image) on Linux
[Blender] How to allow users to control plugins from toolshelf options
How to log in to AtCoder with Python and submit automatically
How to copy and paste command line content without mouse in bash on Linux or mac
How to display a specified column of files in Linux (awk)
How to handle session in SQLAlchemy
How to install OpenCV on Cloud9 and run it in Python
Easy copy to clipboard on Linux
Automatically acquire the operation log in the terminal when logging in to Linux
How to use classes in Theano
How to write soberly in pandas
How to collect images in Python
How to use Dataiku on Windows
How to update Spyder in Anaconda
How to use SQLite in Python
Notes on how to use pywinauto
How to install pycrypto on Windows
How to deploy django-compressor on Windows
Notes on how to use featuretools
How to set up and use OMC Log Analytics --Linux version -
How to install OpenCV on Mac
How to use python put in pyenv on macOS with PyCall
How to install MBDyn (Linux Ubuntu)
How to display PDF resolution and detailed information on Linux (pdfinfo)
How to convert 0.5 to 1056964608 in one shot
How to install PyPy on CentOS
How to use homebrew on Debian
How to get all traffic through VPN with OpenVPN on Linux
Misunderstanding on how to connect cnn