Objective: in a virtual machine automatically get the user and switch from other users for the root user
1, use the command users to check the current user roles
[rhat @ gy20 ~] $users
Root root root root
2, take one as output
[rhat @ gy20 ~] $users | awk '{print $1}
The root
3, the output of the step 2 as input "su - root" command execution, the execution is successful, but not lost password to enter the password this step error and then exit the command automatically, ask how should solve??
[rhat @ gy20 ~] $users | awk '{print $1}' | xargs the su -
Password: su: Authentication failure
[rhat @ gy20 ~] $
CodePudding user response:
Xargs don't know why not, but it can also be: su - ` users | awk '{print $1}' `