# Problem Reproduction Steps:
1. Created user with:
useradd -d /var/www/mywebsite.com -m newuser
passwd newuser
2. SSH login as newuser shows:
- Tab autocomplete fails (inserts space)
- Arrow keys don't show command history
When creating users via useradd
(as opposed to adduser
on Debian-based systems), the system doesn't automatically set up the user's shell environment files. The key files typically missing are:
~/.bashrc
- Contains shell behavior configurations~/.bash_profile
or~/.profile
- Login initialization
First check which shell is assigned to the user:
grep newuser /etc/passwd
# Should show something like:
# newuser:x:1001:1001::/var/www/mywebsite.com:/bin/bash
Here's how to properly set up the environment:
# As root:
cp /etc/skel/.bashrc /var/www/mywebsite.com/
cp /etc/skel/.profile /var/www/mywebsite.com/
chown newuser:newuser /var/www/mywebsite.com/.bashrc
chown newuser:newuser /var/www/mywebsite.com/.profile
# Alternatively, create the files manually:
cat > /var/www/mywebsite.com/.bashrc << 'EOF'
# ~/.bashrc: executed by bash(1) for non-login shells.
[ -z "$PS1" ] && return
PS1='\u@\h:\w\$ '
umask 022
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
EOF
After setting up the files:
ssh newuser@mywebsite.com
# Test tab completion:
cd /var/www/myweb[tab] # Should now complete to mywebsite.com
# Test history:
echo "test command"
[up arrow] # Should now show previous command
For batch user creation, consider these approaches:
# Method 1: Using adduser (Debian/Ubuntu)
adduser --home /var/www/mywebsite.com newuser
# Method 2: Template the skeleton directory
mkdir -p /etc/custom_skel
cp /etc/skel/.bash* /etc/custom_skel/
useradd -k /etc/custom_skel -d /var/www/mywebsite.com -m newuser
If issues persist, check:
# 1. Shell permissions
ls -la /var/www/mywebsite.com | grep bash
# 2. Global completion settings
ls -l /etc/bash_completion.d/
# 3. Terminal type
echo $TERM
# 4. Inputrc configuration
cat /etc/inputrc | grep tab
When creating a new Linux user via useradd
, you might encounter missing shell features like:
- Tab autocomplete not expanding paths
- Command history (arrow keys) not working
- No colored prompt or other shell customizations
This happens because useradd
doesn't automatically create the user's bash configuration files. Unlike adduser
(Debian/Ubuntu) which handles this, useradd
requires manual setup.
Check if the skeleton files were copied:
ssh newuser@mywebsite.com
ls -la ~/
If you don't see .bashrc
, .profile
, and .bash_logout
, we need to create them.
As root, copy the skeleton files:
cp /etc/skel/.bashrc /var/www/mywebsite.com/
cp /etc/skel/.profile /var/www/mywebsite.com/
cp /etc/skel/.bash_logout /var/www/mywebsite.com/
chown newuser:newuser /var/www/mywebsite.com/.bash*
For future users, include the skeleton files during creation:
useradd -d /var/www/mywebsite.com -m -k /etc/skel newuser
On Debian/Ubuntu systems, use the more comprehensive tool:
adduser --home /var/www/mywebsite.com newuser
After implementing any solution:
ssh newuser@mywebsite.com
echo $SHELL
source ~/.bashrc
type -a ls
For web server users, consider adding to .bashrc
:
# Set default umask for web files
umask 002
# Add /usr/local/bin to PATH
export PATH=$PATH:/usr/local/bin
# Useful aliases
alias www='cd /var/www/mywebsite.com'
alias logs='tail -f /var/log/apache2/error.log'
For system-wide defaults, edit /etc/skel/.bashrc
which will be copied to all new users.