Linux Command Tips - User Management

Every user who has access to a Linux system needs a login and apassword. Each user must belong to a primary group and for security oraccess purposes can belong to several secondary groups.

In order to create new logins, modify or delete users, you must already be logged in as root.  The root login is the highest level and only certain individuals should have access to the root account.

useradd - Adding a new user

Options:

  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)
  • -m (Create the user's home directory

Example: To add a new user with

  • a primary group of users
  • a second group mgmt
  • starting shell /bin/bash
  • password of xxxx
  • home directory of roger
  • create home directory
  • a login name of roger

useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger


usermod - Modifying existing user

Options:

  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)

Example: To add the group 'others' to the user roger

usermod -Gothers roger



userdel - Deleting a user

Options:

  • -r (remove home directory)

Example: To remove the user 'roger' and his home directory

userdel -r roger



passwd - User's Password

Options:

  • user's name (Only required if you are root and want to change another user's password)

Example: To change the password for the account you are currently logged in as...

passwd
Enter existing password
Enter new password
Enter new password again (to validate)

Example: To change the password for the user 'roger' (only you are logged in as root)...

passwd roger
Enter existing password (can be either roger's password or root's password)
Enter new password
Enter new password again (to validate)



Where user and group information stored

User names and primary groups are stored in /etc/passwd. This file can be directly edited using the 'vi' editor, although this is not recommended. Format of the file is...

  • User (name normally all lower case)
  • Password (encrypted - only contains the letter 'x')
  • User ID (a unique number of each user)
  • Primary Group ID
  • Comment (Normally the person's full name)
  • Home directory (normally /home/<user name>
  • Default shell (normally /bin/bash)

Each field is separated by a colon.

Passwords for each user are stored in /etc/shadow. This file should only be changed using the passwd command.

Group information is stored in /etc/group. This file can be directly edited using the 'vi' editor. Format of the file is...

  • Group name
  • Group password (hardly ever used)
  • Group ID
  • User names (separated by commas)

Each field is separated by a colon.

Default files

When a new user is created, the default files and directories that are created are stored in /etc/skel.

This directory can be modified to fit your needs. Modifications only effect new users and does not change anything for existing users.



su - Switch User

To switch to another user, use the su command. This is most commonly used to switch to the root account.

Example: To switch to root account...
su
Enter root's passwd

Example: To switch to the user 'roger'...
su roger
Enter roger's or root's passwd

To return to original user, enter exit



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值