• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Setup a sudo Switch to Another User That Has no Password or ssh Key Set in Linux

by admin

This post outlines steps to setup a sudo access to a specific user to switch to another user that has no password of ssh key set.

As test user (having privilede to edit sudoers file), add to the sudoers file with visudo:

$ sudo visudo

the following line is added to sudoers file for the kirk user:

kirk ALL=(spock) NOPASSWD: ALL

With this setting the user ‘kirk’ when logged in can switch to user ‘spock’ even if it hasn’t a password or ssh key set:

$ sudo -iu spock
$ pwd
/home/spock

This will run all the shell profile scripts. If it is only required to change the user without running all the initial shell scripts use instead:

$ sudo -su spock
$ pwd
/home/kirk

Current directory, alias and other normally setting done in .bashrc (if using BASH) are kept.

This is similar to when a password is set and ‘su’ command is used. It can be “su – spock” or just “su spock”. In both these 2 it is required the spock user password.

Filed Under: Linux

Some more articles you might also be interested in …

  1. chkconfig Command Examples in Linux
  2. mh_lint Command Examples
  3. iex Command Examples
  4. ansible-galaxy – Create and manage Ansible roles (Command Examples)
  5. “az appconfig”: Manage App configurations on Azure (Command Examples)
  6. mcs Command Examples
  7. gnucash-cli Command Examples
  8. git commit-tree: Low level utility to create commit objects
  9. readelf: command not found
  10. nmcli device Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright