Linux change or rename user name and UID (user-id)

Note: if usermod is not in your path, you can use "whereis" to find it or add the following to your path:“/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin”.

需要注意的一点就是当你改变了某个用户的uid以后,之前由这个用户创建的目录/文件的owner就变成了老的uid,你必须手动找出所有的这些目录/文件,然后chown命令修改它们的owner。


from: http://www.cyberciti.biz/faq/howto-change-rename-user-name-id/

by Vivek Gite on January 4, 2007 · 34 comments


Q. How do I change user name (rename user name) or UID under Linux operating system?

A. Use the usermod command to change user name under Linux. it modifies the system account files to reflect the changes that are specified on the command line.

Syntax is as follows
usermod -l login-name old-name

Where,

=> The name of the user will be changed from old-name to login_name. Nothing else is changed. In particular, the user's home directory name should probably be changed to
reflect the new login name.

usermod -u UID username

Where,
=> The numerical value of the user's ID (UID) . This value must be unique, unless the -o option is used. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user's home directory will have the file user ID changed automatically. Files outside of the user's home directory must be altered
manually.

Task: Change username from tom to jerry

Type usermod command as follows:
# id tom
# usermod -l jerry tom
# id jerry
# id tom

Task: Change user tom UID from 5001 to 10000

Type usermod command as follows
# id tom
# usermod -u 10000 tom
# id tom

Read man page of usermod for more information.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值