linux重命名用户名_如何在Linux中更改或重命名用户名和用户ID?

本文介绍了如何在Linux系统中更改已创建的用户名或用户ID。首先,使用`cat /etc/passwd`命令列出用户信息。然后,使用`usermod`命令,通过`-l`选项重命名用户名,通过`-u`选项更改用户ID。在进行这些更改后,再次使用`cat /etc/passwd`确认变更是否成功。务必注意,这些更改会影响整个系统。
摘要由CSDN通过智能技术生成
linux重命名用户名

linux重命名用户名

The problem is we want to change the already created user name or user id. As we know there is a lot of configuration those rely on the user id like permissions. We will use usermod command to make this change. Keep in mind this changes will effects system wide.

问题是我们要更改已经创建的用户名或用户ID。 我们知道有很多配置都依赖于用户ID(例如权限)。 我们将使用usermod命令进行更改。 请记住,此更改将影响整个系统。

列出用户信息 (List User Info)

Before starting to big changes we will list users detailed info with cat command like below.

在开始进行较大的更改之前,我们将使用下面的cat命令列出用户的详细信息。

$ cat /etc/passwd | grep ismail

List User Info
List User Info
列出用户信息
  • test is our user name for this operation

    test是此操作的用户名

  • 1000 is the current id of our test user.

    1000是我们测试用户的当前ID。

变更使用者名称 (Change User Name)

We will change username with the following command by providing new username. We will provide the -l option with the new username and old username. In this example we will change username ismail into ali.

我们将通过提供新的用户名,使用以下命令更改用户名。 我们将为-l选项提供新的用户名和旧的用户名。 在此示例中,我们将用户名ismail更改为ali

$ sudo usermod -l ali ismail
  • usermod is command we issue to chage

    usermod是我们发出的命令

  • -l ali is the new username

    -l ali是新的用户名

  • ismail is the original username

    ismail是原始用户名

变更使用者编号(Change User ID)

Another opportunity is changing the user ID. Previously we have listed user information of the ismail . We know that the user id of the ismail is 1000. We will use -u option and the new user id with the user name. In this example we will change the user id of ismail into 1010

另一个机会是更改用户ID。 以前我们已经列出了ismail用户信息。 我们知道ismail的用户ID是1000 。 我们将使用-u选项和带有用户名的新用户ID。 在此示例中,我们将ismail的用户ID更改为1010

$usermod -u 1010 ismail
  • usermod is command used too

    usermod也使用命令

  • -u 1010 is new user id provided for the user

    -u 1010是为用户提供的新用户ID

  • ismail is the user whose id will be changed.

    ismail是将更改其ID的用户。

再检查一次 (Check It Again)

After these steps we need to the if there is a problem or everything is OK. We will list user information again with the cat command like below.

完成这些步骤后,我们需要确定是否存在问题或一切正常。 我们将使用cat命令再次列出用户信息,如下所示。

$cat /etc/passwd | grep test
  • test2 is new username but home directory stays the same

    test2是新的用户名,但主目录保持不变

  • 1010 is the users new id

    1010是用户的新ID

LEARN MORE  How To Add New User Account To Linux
了解更多如何向Linux添加新用户帐户

如何在Linux中更改或重命名用户名和用户ID? 信息 (How To Change or Rename Username and User ID In Linux? Information)

How To Change or Rename Username and User ID In Linux? Information
How To Change or Rename Username and User ID In Linux? Information
如何在Linux中更改或重命名用户名和用户ID? 信息

翻译自: https://www.poftut.com/change-rename-username-user-id-linux/

linux重命名用户名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值