linux系统中的用户账号

一.切换用户

1.su - 用户名

从管理员root切换到普通用户不用输入密码

root@wth-virtual-machine:/home/wth# su - wth
真的困
wth@wth-virtual-machine:~$ 

退出当前用户

exit

wth@wth-virtual-machine:~$ exit
注销
root@wth-virtual-machine:/home/wth# 

2.修改主机名

hostnamectl  set-hostname 主机名

su(刷新)

root@wth-virtual-machine:/home/wth# hostnamectl set-hostname test1
root@wth-virtual-machine:/home/wth# su
root@test1:/home/wth# 

二 .uid号

linux系统中根据uid号来确定账号身份信息

1.超级管理员:

拥有最高权限,唯一,uid号为0

2.普通用户:

权限受限,但在自己的家目录拥有完整权限  uid从1000开始

3.程序用户:

安装软件时,运行需要的账户,不需要登陆 uid号1-999

4.查看用户信息:

cat /etc/passwd

5.查看用户密码信息:

cat /etc/shadow

三.创建用户

1.useradd

centos:直接 useradd 用户

ubuntu:useradd -m -s /bin/bash 用户

2.选项

-m 创建用户时创建家目录

-s 指定用户登录的shell

-u 指定uid号

-d 指定用户的家目录的位置

-m 创建程序用户时,不创建家目录

四.删除用户

userdel

-r 删除用户时一并删除家目录

五.修改用户的密码

1.第一种passwd

1.通式:passwd 用户名

root@test1:/home/wth# passwd wth
新的密码: 
无效的密码: 密码少于 8 个字符
重新输入新的密码: 
passwd:已成功更新密码

2.选项

-d 清空用户的密码,这样才真的不需要密码

-l 锁定用户

-u 解锁用户

-S 查看账号是否被锁定

2.第二种改密码命令行改密码 

1.centos:echo ‘123’ | passwd  --stdin wth

[root@localhost ~]# echo '123' | passwd --stdin wth
更改用户 wth 的密码 。
passwd:所有的身份验证令牌已经成功更新。

2.ubuntu:echo ‘wth:wth123456’ | chpasswd

root@test1:/home/wth# echo 'wth:wthxpy123' | chpasswd

六. 修改账号信息

usermod

-u 修改用户的uid号

-d 修改用户的家目录位置

-e 修改用户的账户有效时间

-G 修改用户的附加组

-s 修改用户的登录shell

-L 锁定用户信息

-U 解锁

七.组账号

1.groupadd 组名

文件位置:/etc/group

2.添加组成员

gpasswd

-a 向组内添加用户id或组id

-d 删除

-M 添加多个组成员,已逗号分开

3.删除组

groupdel 组名

八.系统的用户配置文件

1.全局配置--对所有用户

位置:/etc/profile

source /etc/profile 读取配置文件当中可运行文件,立即生效

2.用户自定义--只对当前用户

位置:用户的家目录  .bashrc/.profile 

九.权限管理

1.修改权限

chmod   修改权限

root@test1:/mnt# ll
总计 20
drwxr-xr-x  5 root root 4096 10月 28 14:45 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
drwxr-xr-x  2 root root 4096 10月 28 14:43 123/
drwxr-xr-x  2 root root 4096 10月 28 14:43 456/
drwxr-xr-x  2 root root 4096 10月 28 14:43 789/
root@test1:/mnt# chmod 777 123
root@test1:/mnt# ll
总计 20
drwxr-xr-x  5 root root 4096 10月 28 14:45 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
drwxrwxrwx  2 root root 4096 10月 28 14:43 123/
drwxr-xr-x  2 root root 4096 10月 28 14:43 456/
drwxr-xr-x  2 root root 4096 10月 28 14:43 789/

2.修改所有者和所在组

chown

root@test1:/mnt# ll
总计 20
drwxr-xr-x  5 root root 4096 10月 28 14:45 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
drwxrwxrwx  2 root root 4096 10月 28 14:43 123/
drwxr-xr-x  2 root root 4096 10月 28 14:43 456/
drwxr-xr-x  2 root root 4096 10月 28 14:43 789/
root@test1:/mnt# chown wth.wth 123
root@test1:/mnt# ll
总计 20
drwxr-xr-x  5 root root 4096 10月 28 14:45 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
drwxrwxrwx  2 wth  wth  4096 10月 28 14:43 123/
drwxr-xr-x  2 root root 4096 10月 28 14:43 456/
drwxr-xr-x  2 root root 4096 10月 28 14:43 789/

 十.小实验

给切换用户时加上欢迎语

1.先创建一个配置文件

root@test1:/opt# vim test1.sh

#!/bin/bash
echo 'zhen de kun'

2.修改文件的权限,让其可以执行

root@test1:/opt# chmod 777 test1.sh
root@test1:/opt# ll
总计 1080
drwxr-xr-x  6 root  root     4096 10月 30 16:54 ./
drwxr-xr-x 20 root  root     4096 10月 28 10:04 ../
-rw-r--r--  1 root  root        0 10月 28 13:59 .000
dr---w---x  2 root  root     4096 10月 30 13:43 123/
drwxr-xr-x  9 nginx nginx    4096 10月 29 16:07 nginx-1.22.0/
-rw-r--r--  1 root  root  1073322 10月 29 09:08 nginx-1.22.0.tar.gz
-rwxrwxrwx  1 root  root       31 10月 30 16:54 test1.sh*
drwxr-xr-x  6 root  root     4096 10月 28 14:44 xy104/
drwxr-xr-x  3 root  root     4096 10月 28 14:15 xy105/

3.在对应用户的家目录下的配置文件中加入此配置文件

root@wth-virtual-machine:/home# vim /home/wth/.profile 

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
/opt/test1.sh
~                                                                                                                         
~                                                                                                                         
~                                                                                                                         
-- 插入 --                                                

4.修改文件所有者和所有组

root@wth-virtual-machine:/home# cd /opt
root@wth-virtual-machine:/opt# chown wth.wth test1.sh
root@wth-virtual-machine:/opt# ll
总计 24
drwxr-xr-x  5 root root 4096 10月 30 17:00 ./
drwxr-xr-x 20 root root 4096 10月 28 10:04 ../
-rw-r--r--  1 root root    0 10月 28 13:59 .000
drwxr-xr-x  2 root root 4096 10月 28 14:05 123/
-rwxrwxrwx  1 wth  wth    31 10月 30 17:00 test1.sh*
drwxr-xr-x  6 root root 4096 10月 28 14:44 xy104/
drwxr-xr-x  3 root root 4096 10月 28 14:15 xy105/

5.source 配置文件,执行文件中可运行部分,立即生效

root@wth-virtual-machine:/opt# source /home/wth/.profile 
zhen de kun

6.切换用户,出现欢迎语

oot@wth-virtual-machine:/opt# su - wth
zhen de kun

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值