【问题标题】:Changing a users shell with a script?使用脚本更改用户外壳?
【发布时间】:2017-06-13 13:40:58
【问题描述】:

是否有适当的方法可以根据用户使用的 shell 使用脚本更改用户的 shell 变量?比如

GITSHELL=/bin/bash
if [ GITSHELL = $SHELL ]
then 
chsh git -s /usr/bin/git-shell
else
chsh git -s /bin/bash

显然这有一些问题。我不知道该怎么说,所以我可以 A: 以 root 身份运行它并且仍然调用用户 git 的 shell 而不是 root 在某处的语句中使用 su 或 B: 以 git 和 su -c root 运行它以在初始 if 之后更改 git 的 shell?

目标是当我需要该用户临时必须能够创建文件夹并运行 git init --bare 时,我可以运行一个脚本来将用户 git 的 shell 更改为 bash。然后出于安全原因,我将再次运行脚本以将 shell 更改回 git-bash。 这是可能的还是我应该以不同的方式解决这个问题?

【问题讨论】:

    标签: linux git bash shell


    【解决方案1】:

    让用户做出决定,通过环境变量控制。只需像这样编写脚本:

    : ${GITSHELL:=/usr/bin/git-shell}
    
    git -s "$GITSHELL"
    

    现在,您的脚本将使用 /usr/bin/git-shell,除非明确覆盖:

    $ ./script.sh                     # use /usr/bin/git-shell
    $ GITSHELL=/bin/bash ./script.sh  # use /bin/bash
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-19
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      相关资源
      最近更新 更多