• 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. How to Install the pip Package in CentOS/RHEL 7 and 8
  2. lvextend command examples in Linux
  3. srun Command Examples in Linux
  4. CentOS / RHEL : How to block incoming and outgoing ports using iptables
  5. Setting up an NFS server with Turnkey Linux
  6. wg: command not found
  7. Xtreme Download Manager(xdman): Internet Download Manager(IDM) For Ubuntu
  8. CentOS / RHEL : How to set chroot jail for vsftp for all the users
  9. coredumpctl Command Examples in Linux
  10. tc: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright