千鹤喵绫 我是大力水手,我喜欢吃菠菜,因此我力大无比!《大力水手》
歌曲封面 未知作品

网站已运行 189 天 10 小时 53 分

Powered by Typecho & Sunny

2 online · 81 ms

Title

CentOS新建用户并授权

千鹤喵绫

·

Article

记录下最近的

图片描述

一、创建新用户
1、创建一个新用户:zero

♾️ shell 代码:
[root@localhost ~]# adduser zero

2、为新用户创建初始化密码

♾️ shell 代码:
[root@localhost~]# passwd zero
Changing password for user prefma.
New password:             # 输入密码(不显示)
Retype new password:      # 再次输入密码(不显示)
passwd: all authentication tokens updated successfully.

二、授权
个人用户的权限只可以在本home下有完整权限,其他目录需要别人授权。经常需要root用户的权限,可以通过修改sudoers文件来赋予权限。
新创建的用户并不能使用sudo命令,需要给他添加授权。
1、查找sudoers文件路径并赋予权限

♾️ html 代码:
[root@localhost~]# whereis sudoers                     # 查找sudoers文件路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
[root@localhost~]# ls -l /etc/sudoers                  # 查看权限
-r--r----- 1 root root 3938 Sep  6  2017 /etc/sudoers  # 只有读权限
[root@localhost~]# chmod -v u+w /etc/sudoers           # 赋予读写权限
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)

2、修改sudoers文件
输入命令 vim /etc/sudoers 修改sudoers文件,添加新用户信息:

♾️ shell 代码:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
zero ALL=(ALL) ALL #这个是新用户

然后输入命令 wq! 保存修改。
3、收回权限

♾️ shell 代码:
[root@localhost~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)

4、新用户登录
新建连接,使用新创建的用户登录,并进行验证,比如:

♾️ shell 代码:
[zero@localhost~]$ pwd
/home/zero
[zero@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers
现在已有 2 条评论,0 人点赞

广告

页底广告 页底广告
Comment
发表
  1. 头像
    @
    John_Smith
    CentOS草
    · Windows · Chrome · 日本CZ88.NET

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
    1. 头像
      @
      是啊,重新回忆以前学的🤔,都忘的差不多了
      · Windows · Chrome · 中国香港特别行政区

      👍

      💖

      💯

      💦

      😄

      🪙

      👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主