如何在shell命令中切换用户

我正在创build一个shell脚本来自动化我们的证书导入过程。 它将以root身份运行以更新组策略。 一旦完成,我们怎么能改变根login用户名在MAC?

例如:

#!/bin/bash VERSION=1 #Internal network check if ping -c 2 source.vmware.com ; then OK ; else echo “Exiting, not connected to internal network” ; fi sudo gpupdate 

发布这个,我们将不得不运行一个命令“SCC”,它将导入证书,但它只作为login的用户(AD用户名)运行? 需要帮忙…

 su -c "your command" username 

在帮助中:

 $ su --help Usage: su [options] [LOGIN] Options: -c, --command COMMAND pass COMMAND to the invoked shell -h, --help display this help message and exit -, -l, --login make the shell a login shell -m, -p, --preserve-environment do not reset environment variables, and keep the same shell -s, --shell SHELL use SHELL instead of the default in passwd