8.2 KiB
SFTP/SSH Account Troubleshooting Guide
Critical Bug Fixed
Password Setting Bug (CRITICAL)
Location: add-sftp.sh line 150
Issue: The password was being set using single quotes which prevented variable expansion when passed through log_cmd function (which uses eval).
Original Code (BROKEN):
log_cmd "echo '$USERNAME:$PASSWORD' | chpasswd" "Setting user password"
Fixed Code:
CHPASSWD_OUTPUT=$(printf '%s:%s\n' "$USERNAME" "$PASSWORD" | chpasswd 2>&1)
CHPASSWD_STATUS=$?
if [ $CHPASSWD_STATUS -eq 0 ]; then
log_success "Password set for user $USERNAME"
else
log_error "Failed to set password for user $USERNAME"
exit 1
fi
Impact: This bug would cause passwords to NOT be set properly, resulting in login failures even if the account was created successfully.
Server Diagnostic Commands
Run these commands on your server as root to diagnose the issue with user mightyuser1:
1. Check if User Exists
id mightyuser1
getent passwd mightyuser1
2. Check User Groups
id -Gn mightyuser1
Expected: User should be in either sftpusers (SFTP-only) or sshusers (SSH+SFTP), and litespeed group.
3. Check User Home Directory
getent passwd mightyuser1 | cut -d: -f6
ls -ld /home/sftpusers/mightyuser1
stat /home/sftpusers/mightyuser1
Expected:
- Home directory should exist at
/home/sftpusers/mightyuser1 - Ownership should be
root:root - Permissions should be
755or751
4. Check Password Status
grep "^mightyuser1:" /etc/shadow | cut -d: -f2
Expected: Should show a hashed password (long string starting with $). If it shows *, !, or is empty, the password is NOT set.
5. Check SSH Configuration
# Check if password authentication is enabled
grep -E "^PasswordAuthentication" /etc/ssh/sshd_config
# Check Match Group configuration
grep -A 5 "Match Group sftpusers" /etc/ssh/sshd_config
grep -A 5 "Match Group sshusers" /etc/ssh/sshd_config
# Check addon config file
cat /etc/ssh/sshd_config.d/99-sftp-addon.conf 2>/dev/null
# Test SSH config syntax
sshd -t
6. Check SSH Service Status
systemctl status sshd
systemctl is-active sshd
7. Check User Creation Logs
# Find the most recent user creation log
ls -t /opt/add-sftp-user-addon/logs/user_creation-*.log | head -1 | xargs cat
# Check error logs
tail -20 /opt/add-sftp-user-addon/logs/errors.log
# Check main log
tail -50 /opt/add-sftp-user-addon/logs/script_output.log
8. Check Directory Structure
# Check if data directory exists and has correct permissions
ls -ld /home/sftpusers/mightyuser1/data
ls -ld /home/sftpusers/mightyuser1/data/ROOT
# Check if ROOT is mounted
mountpoint /home/sftpusers/mightyuser1/data/ROOT
mount | grep "mightyuser1"
9. Check User Shell
getent passwd mightyuser1 | cut -d: -f7
Expected:
/sbin/nologinfor SFTP-only users (should be insftpusersgroup)/bin/bashfor SSH+SFTP users (should be insshusersgroup)
Quick Fixes (Run as Root)
Fix 1: Reset Password
# Replace NEW_PASSWORD with the actual password
echo "mightyuser1:NEW_PASSWORD" | chpasswd
# Verify password was set
grep "^mightyuser1:" /etc/shadow | cut -d: -f2
Fix 2: Fix Group Membership
# For SFTP-only access:
usermod -aG sftpusers,litespeed mightyuser1
usermod -s /sbin/nologin mightyuser1
# For SSH+SFTP access:
usermod -aG sshusers,litespeed mightyuser1
usermod -s /bin/bash mightyuser1
# Verify
id -Gn mightyuser1
Fix 3: Fix Home Directory Permissions
chown root:root /home/sftpusers/mightyuser1
chmod 755 /home/sftpusers/mightyuser1
chown mightyuser1:mightyuser1 /home/sftpusers/mightyuser1/data
chmod 775 /home/sftpusers/mightyuser1/data
Fix 4: Remount ROOT Directory
# Unmount if already mounted
umount /home/sftpusers/mightyuser1/data/ROOT 2>/dev/null
# Remount
mount --bind /var/www/webroot/ROOT /home/sftpusers/mightyuser1/data/ROOT
# Verify
mountpoint /home/sftpusers/mightyuser1/data/ROOT
Fix 5: Enable Password Authentication (if disabled)
# Check current setting
grep "^PasswordAuthentication" /etc/ssh/sshd_config
# Enable if disabled
sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
# Restart SSH service
systemctl restart sshd
Code Analysis
Algorithm Review
The account creation process follows these phases:
- Pre-flight Checks: Validates environment and required directories exist
- System Preparation: Configures SSH/SFTP service and ensures password auth is enabled
- Username Validation: Validates username format (3-32 chars, alphanumeric + underscore)
- User Existence Check: Prevents duplicate users
- Group Setup: Creates
sftpusersandsshusersgroups if needed - Directory Setup: Creates
/home/sftpuserswith proper permissions - User Creation: Creates user with appropriate shell (
/bin/bashfor SSH,/sbin/nologinfor SFTP-only) - Password Setting: FIXED - Now uses
printfto properly set password - Chroot Setup: Sets up chroot jail structure with proper ownership
- Bind Mount: Creates bind mount for webroot access
- Group Assignment: Adds user to appropriate groups (
sftpusersorsshusers+litespeed)
Potential Issues Identified
- FIXED: Password setting bug (single quotes preventing variable expansion)
- Configuration Duplication: Both
manifest.jpsandsystem_prep.shconfigure SSH, which could cause conflicts - Password Special Characters: The fix uses
printfwhich handles special characters better thanecho - SSH Config File Location: The code creates config in
/etc/ssh/sshd_config.d/99-sftp-addon.confbut also modifies main/etc/ssh/sshd_config- ensure Include directive exists
Recommendations
- Deploy the fix - The password setting bug is critical and must be fixed
- Test password reset - For existing users created with the bug, reset their passwords
- Verify SSH config - Ensure
/etc/ssh/sshd_configincludesInclude /etc/ssh/sshd_config.d/*.conf - Check logs - Review user creation logs to see if password setting failed silently
Using the Diagnostic Script
A comprehensive diagnostic script check-sftp-user.sh has been created. Upload it to your server and run:
chmod +x check-sftp-user.sh
./check-sftp-user.sh mightyuser1
This script will check all aspects of the user account and provide detailed diagnostics.
Quick Fix: Webroot Write Permissions
If users cannot create folders or files in the ROOT directory, run this standalone fix script:
# Download and run the fix script
wget https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/fix-webroot-permissions.sh
chmod +x fix-webroot-permissions.sh
sudo ./fix-webroot-permissions.sh
Or manually fix:
# Ensure litespeed group exists
groupadd -f litespeed
# Set group ownership
chgrp -R litespeed /var/www/webroot/ROOT
# Add group write permissions
chmod -R g+w /var/www/webroot/ROOT
# Verify
ls -ld /var/www/webroot/ROOT
# Should show: drwxrwxr-x or drwxrwsr-x (group has write)
Note: The addon code (version 0.7+) automatically fixes this during installation or when creating new users. If you have an existing installation, either:
- Update/reinstall the addon, OR
- Run the fix script above
Common Issues and Solutions
Issue: "Permission denied" when logging in
Causes:
- Password not set (most likely due to the bug)
- User in wrong group
- Password authentication disabled in SSH config
- Home directory permissions incorrect
Solution: Run diagnostic commands above, then apply appropriate fixes.
Issue: User can connect but cannot access files
Causes:
- User not in
litespeedgroup - ROOT directory not mounted
- Data directory permissions incorrect
Solution: Check group membership and mount status, fix as needed.
Issue: SSH works but SFTP doesn't (or vice versa)
Causes:
- User in wrong group (
sftpusersvssshusers) - Shell mismatch (
/sbin/nologinvs/bin/bash) - SSH config Match Group rules incorrect
Solution: Verify group membership and shell match the desired access type.