Linux创建新用户时遇到的问题记录
作者:互联网
创建新用户命令:
useradd -d "/home/guest" -m -s "/bin/bash" guest
报错:
useradd: cannot open /etc/passwd
按照网上的解决方案:
chattr -ia /etc/passwd
此时/etc/passwd的属性:
--------------e----- /etc/passwd
继续执行:
useradd -d "/home/guest" -m -s "/bin/bash" guest
继续报错:
useradd: cannot open /etc/passwd
继续查经验贴:
查到大概是因为是用的windows命令行登录Linux的原因,解决方案:
# 我这里是centOS,Ubuntu可以用 apt install dos2unix
yum install dos2unix
sudo dos2unix /etc/passwd
作者原文:
You most likely introduced some error in the
passwd
's syntax. You need to fix it.Might be through editing from Windows you have introduced Windows line endings, try:
sudo apt install dos2unix sudo dos2unix /etc/passwd
英语好的可以自行理解,文章出处:https://askubuntu.com/questions/1339468/useradd-cannot-open-etc-passwd
总结:
第一步:
chattr -ia /etc/passwd
第二布:
yum install dos2unix
sudo dos2unix /etc/passwd
第三步设置密码:
passwd guest
标签:guest,passwd,创建,sudo,用户,etc,useradd,Linux,dos2unix 来源: https://www.cnblogs.com/GreenOrange/p/15957112.html