SSH to server, Sudo su - then run commands in bash [duplicate]

元气小坏坏 提交于 2019-12-03 06:02:22

Try

ssh -t $USER@server006.web.com 'sudo -u http grep -i "Exception:" /opt/local/server/logs/exceptions.log | grep -e "|*-*-*:*:*,*|" | tail -1 | awk -F"|" "{print $2}" >> log.log'

Sudo already runs the command as a different user to there's no need to su again.

Only reason to do sudo su is to have a fast way to start a new shell with another user.

You probably want sudo -u instead of sudo su -:

ssh -t $USER@server006.web.com sudo -u http script 

Guess I'm late to the party. My solution:

ssh -t $USER@server006.web.com "sudo cat /etc/shadow"

and replace cat /etc/shadow with your desired program.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!