How to Switch Between Users Without Password in Linux

August 1, 2025 / Servers, Hosting & Email

This guide explains how to switch between users without a password in Linux.

Switching users in Linux usually requires entering a password. However, there are safe ways to configure your system to allow certain users to switch accounts without a password prompt. This can be useful for administrative scripts, automation, or trusted environments.

Using ‘sudo’ Without a Password
The safest and most common method is configuring sudo for passwordless switching.

  1. Edit the sudoers file
    Open the sudoers file using the visudo command:

    sudo visudo
  2. Add a passwordless entry
    Add the below line at the termination of the file:

    username ALL=(targetuser) NOPASSWD: ALL
    • username ? The current user.
    • targetuser ? The user you want to switch to.
  3. Switch user
    Now you can switch users without entering a password:

    sudo -u targetuser -i

    Or:

    sudo su - targetuser

Using ‘su’  With Passwordless Access (Optional)
You can let ‘su’ switch users without a password by changing PAM (Pluggable Authentication Modules). Warning: This process is less protected.

  1. Backup PAM configuration
    sudo cp /etc/pam.d/su /etc/pam.d/su.bak
  2. Edit PAM configuration
    Open the file:

    sudo nano /etc/pam.d/su

    Comment out the line:

    auth       required   pam_wheel.so

    Or adjust it according to your distro to allow specific users.
    Note: This is not recommended on production systems due to security risks.

Using SSH Key-Based Authentication (For Remote Switching)
If switching users remotely via SSH:

  1. Generate SSH keys
    ssh-keygen -t rsa
  2. Copy the public key to the target user:
    ssh-copy-id targetuser@localhost
  3. Switch user via SSH without a password:
    ssh targetuser@localhost

Security Considerations:

  • Only grant passwordless access to trusted users.
  • Avoid enabling passwordless su in production environments.
  • Prefer sudo NOPASSWD for controlled switching.
  • Always back up configuration files before editing.

This way, you can switch between users without a password in Linux.  Hope you liked our article. If you want additional assistance, feel free to contact our support staff.

Want easier access too? Learn How to Enable Passwordless SSH Login in Linux

Managing multiple user accounts and permissions on Linux servers?
A Linux VPS Hosting solution gives you full control over user access, account management and administrative privileges in a secure server environment.
Spread the love