Linux创建新用户时遇到的问题记录
创建新用户命令:
1 | useradd -d "/home/guest" -m -s "/bin/bash" guest |
报错:
1 | useradd: cannot open /etc/passwd |
按照网上的解决方案:
1 | chattr -ia /etc/passwd |
此时/etc/passwd的属性:
1 | --------------e----- /etc/passwd |
继续执行:
1 | useradd -d "/home/guest" -m -s "/bin/bash" guest |
继续报错:
1 | useradd: cannot open /etc/passwd |
继续查经验贴:
查到大概是因为是用的windows命令行登录Linux的原因,解决方案:
1 | 我这里是centOS,Ubuntu可以用 apt install dos2unix |
作者原文:
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:
1
2 sudo apt install dos2unix
sudo dos2unix /etc/passwd
英语好的可以自行理解,文章出处:https://askubuntu.com/questions/1339468/useradd-cannot-open-etc-passwd
总结:
第一步:
1 | chattr -ia /etc/passwd |
第二布:
1 | yum install dos2unix |
第三步设置密码:
1 | passwd guest |