为什么sudo su; su的tomcat不能切换到tomcat用户?

在Redhat linux中。 从我的用户如果我发出命令sudo su – >更改为根su – tomcat – >更改为tomcat用户

为什么拖尾单行命令不起作用? sudo su; su tomcat – > stil在根目录下。 不切换到tomcat

命令

sudo su; su tomcat 

是两个命令。 shell将运行第一个,当它完成时它将运行第二个。 请注意,shell不会将第二个命令作为parameter passing给第一个命令。

当你退出第一个命令时,它将运行第二个命令

 sudo su ; su tomcat [sudo] password for iain: root@host:iain]$ exit exit Password: <---- this is the prompt from the second su command. 

你可以使用sudo直接转换到tomcat用户

 sudo -u tomcat <some command> 

或使用-s来获得一个shell例如

 whoami iain sudo -s -u tomcat whoami tomcat 

当你用sudosu命令分割你的sudosu命令时; 签署su将在sudo完成后执行。 即在这种情况下,你执行su作为你的普通用户。

为了达到你想要的效果,试着用一个命令来执行整个命令:

 sudo su - tomcat