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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. mkdir and rmdir Command Examples in Linux
  2. loadkeys: command not found
  3. How to Create yum Repository in CentOS/RHEL
  4. pacman –upgrade Command Examples in Linux
  5. What are SELinux Modes and how to set them
  6. How to uninstall fail2ban on Ubuntu
  7. lsb_release: command not found
  8. Troubleshooting “connection refused” From Remote Servers in CentOS/RHEL 7 (Either Firewalld or iptables service issue)
  9. pdftoppm Command Examples in Linux
  10. How to set “max_report_luns” and “max_luns” on CentOS/RHEL 7 to scan more than 16,383 LUNs

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright