如何以其他用户身份登录,然后以bash脚本注销? [英] How to login as another user and then log out in bash script?

查看:63
本文介绍了如何以其他用户身份登录,然后以bash脚本注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个bash脚本来以其他用户身份执行操作,然后返回到初始用户...

I need to write a bash script to do something as another user and then return to the initial user...

假设我以root身份运行以下命令:

Suppose I run the following as root:

#!/bin/bash
USER=zaraza
su - "${USER}"
#do some stuff as zaraza
________ #here I should logout zaraza
#continue doing things as root

在控制台中,我应该写"exit",但是在bash中是一个关键字,它会退出脚本...

In the console I should write "exit", but in bash is a keyword and it exits the script...

预先感谢

推荐答案

使用 su -c .在手册页中:

 su man -c catman
        Runs the command catman as user man.  You will be asked for man's
        password unless your real UID is 0.

这篇关于如何以其他用户身份登录,然后以bash脚本注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆