首页 > 解决方案 > 创建用户帐户时缺少命令提示符用户名 - Linux - Debian?

问题描述

我正在编写一个 bash 脚本来创建带有密码的用户帐户,该密码将过期。创建用户帐户然后使用 su - 登录后,我收到提示,但提示中缺少用户 ID。此外,缺少选项卡自动完成功能。这是我的 bash 脚本。请记住,我在 Windows - WSL2 中使用 Debian 9。

#!/bin/bash

# This script creates an account on the local system.
# You will be prompted for the account name and password.

# Ask for the user name.
read -p 'Enter the username to create: ' USER_NAME

# Ask for the real name.
read -p 'Enter the name of the person who this account is for: ' COMMENT

# Ask for the password
read -p 'Enter the password to use for the account: ' PASSWORD

# Create the user 
useradd -c "${COMMENT}" -m ${USER_NAME}

# Set the password for the user.
# echo ${PASSWORD} | passwd --stdin ${USER_NAME}

echo "${USER_NAME}:${PASSWORD}" | chpasswd

# Force password change on first login.
passwd -e ${USER_NAME}

运行此程序后,我会在左侧收到一个提示,其中没有用户 ID。此外,使用选项卡的自动完成功能不起作用。我有点惊讶,我在这里做错了吗?

这就是我所看到的。

在此处输入图像描述

标签: linuxbashdebian

解决方案


使用 adduser 命令而不是 useradd 添加用户。Inscript 总是用户 adduser。在 Debian 盒子上测试了相同的脚本,它工作正常。


推荐阅读