Home > Operation and Maintenance > Linux Operation and Maintenance > How to create users, add and modify shells in Linux

How to create users, add and modify shells in Linux

王林
Release: 2023-05-30 23:29:40
forward
3673 people have browsed it

1. Create user

useradd -d /test -s /bin/bash -m test
Copy after login
  • -d: Specify the user’s home directory

  • -s : User’s login shell

  • -m: Create user home directory

Create password:

passwd test然后输入两遍新密码
Copy after login

2. View the created users

vim /etc/passwd
Copy after login
Copy after login

This file records the information of all users, with 7 pieces of information separated by 6 colons: For example: root:x:0:0:root: /root:/bin/bash

How to create users, add and modify shells in Linux

How to create users, add and modify shells in Linux

3. Modify the user’s login shell

1) Command modification:

usermod -s /sbin/nologin test
usermod -s /bin/false test
...
Copy after login

2) Directly modify the /etc/passwd file:

vim /etc/passwd
Copy after login
Copy after login

How to create users, add and modify shells in Linux

4. The user’s login shell

shell is where the user communicates with the computer As a medium, the login shell ensures communication between the user and the computer, while the non-login shell cannot allow the computer to communicate with the user. Information recording the user's default login shell is stored in the /etc/passwd file.

  • Login shell can be used by users to log in, such as /bin/bash,/bin/sh,/bin/csh...General Linux The default user shell is bash, which means you can log in and write commands.

  • Non-login shell: The classic /bin/nologin is a non-login shell, that is to say, if a user defaults to it, even if the user logs in Linux cannot use linux either.

Non-login shell has its own specific use. For example, if you build an ftp server using Linux and create multiple users, you can change the default shell of these users to nologin, so First, although these users are users on Linux, they cannot log in to the Linux host and can only enter the ftp server, which also ensures security!

For example:

//登录shell
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
//非登录shell
/sbin/nologin
/bin/false
...
Copy after login
  • ##/bin/false: Do nothing but return an error status, then immediately quit. If the user's shell is set to /bin/false, the user will be unable to log in and there will be no prompt.

  • /sbin/nologin: Will politely display a message to the user and refuse the user to log in: This account is currently not available. There are some software, such as some FTP server software, for local non-virtual accounts, only users with a valid shell can use the FTP service. At this time, you can use nologin to prevent users from logging in to the system and still using some system services, such as ftp services. /bin/false does not work, this is one of the important differences between the two.

  • /etc/nologin: If the /etc/nologin file exists, the system only allows the root user to log in, and all other users are denied login, and a message is displayed to them The contents of the /etc/nologin file.

The above is the detailed content of How to create users, add and modify shells in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template