Score:0

Ubuntu22.04: useradd don't work as expected

cm flag

I setup a factory new ubuntu 22.04.

I run useradd test1, there is no home directory created.

I run useradd -m test2, there is home directory with ~/.bashrc and some other environment files. But the bash script doesn't seem to work: here is a screenshot

root@jenkins-slave02:/home# useradd -m test3
root@jenkins-slave02:/home# su - test3
$
$
$
$ ls -la
total 20
drwxr-x--- 2 test3 test3 4096 Jun  7 05:15 .
drwxr-xr-x 5 root  root  4096 Jun  7 05:15 ..
-rw-r--r-- 1 test3 test3  220 Jan  6  2022 .bash_logout
-rw-r--r-- 1 test3 test3 3771 Jan  6  2022 .bashrc
-rw-r--r-- 1 test3 test3  807 Jan  6  2022 .profile
$ set
HOME='/home/test3'
IFS='
'
LANG='en_US.UTF-8'
LOGNAME='test3'
MAIL='/var/mail/test3'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
PPID='4019868'
PS1='$ '
PS2='> '
PS4='+ '
PWD='/home/test3'
SHELL='/bin/sh'
TERM='xterm'
USER='test3'
XDG_DATA_DIRS='/usr/local/share:/usr/share:/var/lib/snapd/desktop'
_='-la'
snap_bin_path='/snap/bin'
snap_xdg_path='/var/lib/snapd/desktop'
$
$ cd /etc/skel
$ ls
$ ls -la
total 20
drwxr-xr-x   2 root root 4096 Feb 17 17:23 .
drwxr-xr-x 105 root root 4096 Jun  7 05:15 ..
-rw-r--r--   1 root root  220 Jan  6  2022 .bash_logout
-rw-r--r--   1 root root 3771 Jan  6  2022 .bashrc
-rw-r--r--   1 root root  807 Jan  6  2022 .profile
$ pwd
/etc/skel
$

I don't modify /etc/skel, and here is my useradd -D output

root@jenkins-slave02:/home# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
root@jenkins-slave02:/home#

I don't know why. Please help.

muru avatar
us flag
Please don't post screenshots of text. Copy the text here and use code formatting: https://askubuntu.com/editing-help#code. And what is that screenshot supposed to show?
Bryan Chen avatar
cm flag
Hello @muru I update the text. I want to say some environment variable don't work. For example `PS1`, there is no shell promt, no keyboard shortcuts like `tab` is act as `\t` not bash complete and so on...
Bryan Chen avatar
cm flag
I find out that the reason is `SHELL=/bin/sh`, not `bash`
muru avatar
us flag
You can set the default value for `SHELL` in `/etc/default/useradd`
Bryan Chen avatar
cm flag
yes, really appreciated.
Score:0
cm flag

According to What is the difference between adduser and useradd?. I realized there is another command adduser in ubuntu.

Bryan Chen avatar
cm flag
So I have one more question, How do I use ansible `user` module to hit `adduser` effect?
Bryan Chen avatar
cm flag
The root cause is default shell is `/bin/sh` not `/bin/bash`. Add `shell: /bin/bash` in ansible will do.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.