如何从Shell在Ubuntu上添加和删除用户

Linux users can be added with different ways. but one of the most used way is adding them throughout the shell because Linux admins loves shell usage. In this tutorial we will look how to add user into a Ubuntu, Kali, Mint, Debian box and provide or change required parameters. We will also look user deletion.

可以使用不同的方式添加Linux用户。 但是最常用的方法之一是在整个shell中添加它们,因为Linux管理员喜欢使用shell。 在本教程中,我们将研究如何将用户添加到Ubuntu,Kali,Mint,Debian框中以及提供或更改所需的参数。 我们还将查找用户删除。

根特权 (Root Privileges)

In order to add or remove user from a Linux box we need root privileges. We can get root privileges with different ways. We can login to root account like below.

为了在Linux系统中添加或删除用户,我们需要root权限。 我们可以通过不同的方式获得root特权。 我们可以如下登录到root帐户。

$ su -

OR we can use sudo  command which operates given command with the current user but with root privileges.

或者我们可以使用sudo命令,该命令以当前用户但具有root特权的方式操作给定命令。

$ sudo ls

使用adduser添加用户 (Add User with adduser)

We can use adduser  command in order to add user.  We will add user named poftut . This command will ask user detailes step by step. At the end of the process we will accept adding given user with Yes\no question.

我们可以使用adduser命令来添加用户。 我们将添加名为poftut用户。 该命令将逐步询问用户详细信息。 在该过程结束时,我们将接受使用“ Yes\no问题添加给定用户。

$ sudo adduser poftut
Add User with adduser 
Add User with adduser  
使用adduser添加用户 

使用useradd添加用户(Add User with useradd)

useradd is the fastest way to add user. useradd will not look for any user detail. Just add user to the Linux box. But it will not configure any password for the given user so we should set recently added user password with passwd like below. In this test we will add user named test1 and change its password.

useradd是添加用户最快的方法。 useradd将不查找任何用户详细信息。 只需将用户添加到Linux框中即可。 但是它不会为给定的用户配置任何密码,因此我们应该使用passwd设置最近添加的用户密码,如下所示。 在此测试中,我们将添加名为test1用户并更改其密码。

$ sudo useradd test2
$ sudo passwd test2
Add User with useradd
Add User with useradd
使用useradd添加用户

删除用户(Delete User)

We can easily delete existing user with userdel  command. In the following example we will delete user named test1 . We need root privileges again.

我们可以使用userdel命令轻松删除现有用户。 在下面的示例中,我们将删除名为test1用户。 我们再次需要root特权。

$ sudo userdel test2
LEARN MORE  How To Disable or Lock Linux User Account?
了解更多如何禁用或锁定Linux用户帐户?

翻译自: https://www.poftut.com/add-delete-user-ubuntu-shell/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值