For a Linux desktop system using the SysV init system and where you are starting without a GUI login manager (e.g., you're booting into a text mode console), implementing a feature where the TTY prompts only for the password of a preconfigured username (similar to the behavior of a GUI login manager that remembers your username) requires creating a custom solution.
The traditional login process involves getty spawning login, which then prompts for a username and password. To alter this behavior, you would need a mechanism to bypass the username prompt while securely handling the authentication process.
Here's a basic approach using agetty's automatic login feature combined with a custom script:
Step 1: Create a Custom Script for Password Prompt
- Create a Script to Prompt for Password:
First, you need to write a script that will be called in place of the usual login process for your user. This script should prompt for the user's password and then validate it. If valid, it should proceed to create a shell for the user.
- Create a script named
/usr/local/bin/custom-login.sh (ensure it is executable):
#!/bin/bash
# Configuration
USERNAME="yourUsername"
# Prompt for Password
read -s -p "Password for $USERNAME: " PASSWORD
echo
# Validate the Password
if echo "$PASSWORD" | su - "$USERNAME" -c 'exit' 2>/dev/null; then
# Start the shell if the password is correct
exec su - "$USERNAME"
else
echo "Login failed"
exec /usr/local/bin/custom-login.sh # Optionally retry on failure
fi
Make sure to replace "yourUsername" with your actual username.
- Make the script executable:
chmod +x /usr/local/bin/custom-login.sh
Step 2: Configure agetty for Automatic Login
You will need to edit the agetty arguments in the service configuration for the TTYs you are using. This is typically found in /etc/inittab on SysV init systems.
- Find the line that configures the TTY you are interested in (e.g.,
tty1) and modify it to call your script:
1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 linux
Change it to:
1:2345:respawn:/sbin/agetty --autologin root --login-program /usr/local/bin/custom-login.sh --noclear tty1 linux
The key parts here are the --autologin root and --login-program /usr/local/bin/custom-login.sh options. --autologin is used to skip the usual login prompt, and --login-program specifies your custom login script. Here, root is used temporarily to initiate the script, but the script will switch to your user assuming correct credential input.
Step 3: Testing and Security Considerations
- Test your setup: After configuring, test the setup by rebooting or issuing
telinit q to tell init to re-examine the /etc/inittab file.
- Security Concerns: Using custom scripts like this can introduce security issues, especially if not properly secured and audited. For instance, storing passwords in plaintext, or executing programs as root without careful validation, can expose your system to risks.
- Improvements: This is a basic approach. Depending on security needs and system setup, it might be necessary to enhance the script, particularly around password handling and validation.
This setup customizes the login process for a SysV init system without a GUI, creating a more convenient login procedure while trying to maintain security. Always review and test such customizations thoroughly to ensure they meet your needs and security requirements.