Commands will not pass to CLI after logging into new user with sudo su - user

前端 未结 1 552
栀梦
栀梦 2021-01-28 14:12

Obligatory \'first post\' tag. Issue: Commands will not pass to command line after entering password for a sudo su - userB

I am writing a s

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 14:23

    su creates a subshell that reads the commands from standard input by default. It executes whoami after that exits. You can use the -c option to pass a command to it.

    ssh -qt -p22 userA@hostname "whoami; sudo su - userB -c 'whoami'"
    

    You can also use the -u option to sudo instead of using su:

    ssh -qt -p22 userA@hostname "whoami; sudo -u userB whoami"
    

    0 讨论(0)
提交回复
热议问题