之前买了一台阿里云服务器,准备用来搭建一些服务,由于使用root用户登录进行操作比较敏感,就新建了一个用户,用来登录并进行日常操作。这篇博客,介绍下centos7.4下如何新建用户并且授权。。。 一、创建新用户...

之前买了一台阿里云服务器,准备用来搭建一些服务,由于使用root用户登录进行操作比较敏感,就新建了一个用户,用来登录并进行日常操作。
这篇博客,介绍下centos7.4下如何新建用户并且授权。。。
一、创建新用户
1、创建一个新用户:prefma
[root@localhost ~]# adduser prefma
2、为新用户创建初始化密码
[root@localhost~]# passwd prefma Changing password for user prefma. New password: # 输入密码 Retype new password: # 再次输入密码 passwd: all authentication tokens updated successfully.
二、授权
个人用户的权限只可以在本home下有完整权限,其他目录需要别人授权。经常需要root用户的权限,可以通过修改sudoers文件来赋予权限。
新创建的用户并不能使用sudo命令,需要给他添加授权。
1、查找sudoers文件路径并赋予权限
1 [root@localhost~]# whereis sudoers # 查找sudoers文件路径 2 sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz 3 [root@localhost~]# ls -l /etc/sudoers # 查看权限 4 -r--r----- 1 root root 3938 Sep 6 2017 /etc/sudoers # 只有读权限 5 [root@localhost~]# chmod -v u+w /etc/sudoers # 赋予读写权限 6 mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
2、修改sudoers文件
输入命令 vim /etc/sudoers 修改sudoers文件,添加新用户信息:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
prefma ALL=(ALL) ALL #这个是新用户
然后输入命令 wq! 保存修改。
3、收回权限
[root@localhost~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)
4、新用户登录
新建连接,使用新创建的用户登录,并进行验证,比如:
[prefma@localhost~]$ pwd
/home/prefma
[prefma@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers
更多关于Linux和centos的内容,可以关注Linux公社。。。
本文标题为:Linux:CentOS7.4新建用户并授权


基础教程推荐
- 实战Nginx_取代Apache的高性能Web服务器 2023-09-29
- Apache Hudi数据布局黑科技降低一半查询时间 2022-10-06
- apache和nginx结合使用 2023-09-10
- IIS 6 的 PHP 最佳配置方法 2022-09-01
- centos 7 安装及配置zabbix agent 2023-09-24
- linux下安装apache与php;Apache+PHP+MySQL配置攻略 2023-08-07
- nginx.conf(centos7 1.14)主配置文件修改 2023-09-23
- 服务器添加git钩子的步骤 2022-12-12
- Apache服务器配置攻略3 2022-09-01
- linux之conda环境安装全过程 2023-07-11