Linux 创建用户、组,管理权限

  1. 添加用户
    默认目录:
->useradd -m  USERNAME

制定目录:

->useradd -m -d /PATH/TO/FOLDER USERNAME

制定默认的shell

-> useradd  -d  /home/username  -m  username  -s  /bin/bash

BTW: to switch user

-> su another_user

2、设置密码

-> sudo passwd USERNAME
Enter new Unix password:
Retype new Unix password

3、source 或 .无法解析

Shell设置:/bin/sh -> /bin/bash

错误: shell脚本中含有source命令运行时提示 source: not found

测试:
运行 ls -l /bin/sh 后显示/bin/sh -> dash
这说明是用dash来进行解析的。

解决方案:
命令行执行:dpkg-reconfigure dash(需要root权限)
在界面中选择no
再运行ls -l /bin/sh 后显示/bin/sh -> bash

最后测试shell脚本,可以正常使用!

4、添加组

-> groupadd -g Group_ID Group_Name
-> sudo groupadd -g 10000 students

查看组信息:
To check the group belongs

->id -Gn student0
student0 students
-> groups student1 
student1 : student1 students

it says student0 belongs groups student0 and students, so student0 itself is a group named with its username, it also belongs to group students.

5、添加或删除用户到组
sudo usermod -a -G group username
sudo deluser username group
Gnome System Tools
sudo apt-get install gnome-system-tools

6、设置用户与组的权限

查看文件或文件夹的权限:
getfacl DIR

给与组或用户权限:
setfacl -Rm g:groupname:rx DIR
准予组groupname读和执行的权利,-R包涵DIR里面所有文件与子目录,-m在原有的基础上修改。

  1. to enable SSH access
->sudo apt update
->sudo apt install openssh-server

SSH server will start automatically, to check if SSH server is runing or not

-> sudo systemctl status ssh

you will get

● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Mon 2020-06-01 12:34:00 CEST; 9h ago
...

Ref:
chmod 命令在线设置命令
https://chmodcommand.com/chmod-751/
https://www.pluralsight.com/blog/it-ops/linux-file-permissions
https://www.techonthenet.com/linux/sysadmin/ubuntu/create_group_14_04.php
https://www.computerhope.com/unix/usetfacl.htm

你可能感兴趣的:(Linux 创建用户、组,管理权限)