维护伺服器存取权限

使用者

我如何看到系统内的使用者列表清单? 您可以在 /etc/passwd 这个档案内看到这台伺服器的使用者清单,请输入下列指令查看:

cat /etc/passwd 

你会看到很像如下的结果:

eric:x:1006:1006::/home/eric:/bin/sh
john:x:1007:1007::/home/john:/bin/sh
sibelius:x:1007:1007::/home/sibelius:/bin/sh

变更您的密码

要变更您的密码,请先使用您的帐号登入伺服器内(假设是 root),然后输入下列指令:

passwd

接下来您需要输入新密码。在提示符号后面输入:

Enter new UNIX password:

…请再输入一次密码来确认:

Retype new UNIX password:

如果您输入两次相同的密码,你将可以看到下列成功讯息:

passwd: password updated successfully

使用 root 来变更其他使用者的密码

如果您是使用 'root' 登入伺服器并且您想要变更其他使用者的密码,请输入下列指令(假设 billy 是其中一个使用者):

passwd billy

您会被要求输入密码与再次输入来确认密码:

Enter new UNIX password:
Retype new UNIX password:

如果成功,您将会看到下列讯息:

passwd: password updated successfully

建立其他使用者

为了让其他人能够登入您的主机,你需要帮他们建立使用者帐号。请在命力提示符号后面输入下列指令(请将 freya 替换成您要建立的帐号名称):

adduser freya

如下,系统将会询问您几个问题,简易回答这些问题即可:

Adding user `freya' ...
Adding new group `freya' (1004) ...
Adding new user `freya' (1005) with group `freya' ...
Creating home directory `/home/freya' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for freya
Enter the new value, or press ENTER for the default
      Full Name []: freya freyasson
      Room Number []:
      Work Phone []:
      Home Phone []:
      Other []: my cat
Is the information correct? [y/N] y

删除使用者

要删除您的使用者帐号,请在命令提示符号后面输入如下指令(请将 phil 替换成您要删除的帐号):

userdel -r phil

注意: 使用 -r 选项将会移除使用者家的家目录与所有档案,包含使用者的邮件。

群组

建立群组

要建立群组,请在命令提示符号后面出入下列的指令(请将 friends 替换成您要建立的群组名称):

groupadd friends

管理使用者群组

将使用者增加到群组

在建立使用者的时候

在建立使用者的时候可以直接将他加入其他群组内,请在命力提示符号后面输入以下指令(请将 'friends' 更换成您的群组,'eric' 更换成您的使用者):

useradd -g friends eric

(您可以参考 man useradd 来查询其他选项)

在使用者已经存在时

usermod -g friends eric

(您可以参考 man useradd 来查询其他选项)

最后更改: 2016/06/08 08:47 (外部编辑)