为不在 /etc/passwd 中的用户设置默认 shell 为 bash

dot*_*hen 6 command-line bash active-directory

在我公司的 Ubuntu 15.10 桌面系统上,我使用一些基于PBIS 的魔法通过 Active Directory 登录。因此,即使我的主目录在/home/local/FOOBAR/dotancohen/. 当没有要编辑的 /etc/passwd 行因此无法使用时,如何将 bash 配置为 shell chsh

我在这台机器上有另一个具有管理员访问权限的帐户,因此我可以根据需要将系统配置为管理员。但是,如果有一个仅限用户使用的解决方案,我希望将来在我没有管理员访问权限时使用它!

以下是在 Unity(Ubuntu 桌面)中打开 Gnome 终端运行的几个关键命令的结果:

$ echo $HOME
/home/local/TECHMARKETING/dotan
$ whoami
FOOBAR\dotancohen
$ grep dotan /etc/passwd
$ grep sourced ~/.profile
echo 'sourced .profile'
$ grep sourced ~/.bashrc
echo "sourced .bashrc"
$ echo $SHELL
/bin/sh
$ echo $TERM
xterm
$ bash
sourced .bashrc
 - dotan-tm():~$ echo $SHELL
/bin/sh
 - dotan-tm():~$ echo $TERM
xterm-256color
Run Code Online (Sandbox Code Playgroud)

可以看出,当它们被获取时,.bashrc和 都.profile回显。似乎.profile在默认 shell 启动时不运行,而是.bashrc在 bash 启动时运行。我使用此答案从 dash 打开 bash,但由于.profile显然没有运行该脚本没有任何效果。

这是我的完整~/.profile文件以供参考:

$ cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.bin" ] ; then
    PATH="$HOME/.bin:$PATH"
fi

xmodmap ~/.Xmodmap

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

case $- in
  *i*)
    # Interactive session. Try switching to bash.
    if [ -z "$BASH" ]; then # do nothing if running under bash already
      bash=$(command -v bash)
      if [ -x "$bash" ]; then
        export SHELL="$bash"
        exec "$bash" -l
      fi
    fi
esac

echo 'sourced .profile'
$ 
Run Code Online (Sandbox Code Playgroud)

小智 8

使用 PBIS,您可以为所有用户定义默认 shell:

#/opt/pbis/bin/config LoginShellTemplate /bin/bash
Run Code Online (Sandbox Code Playgroud)

这要以 root 身份完成,用户或非特权用户无法更改此设置。这将是所有 AD 用户的默认 shell。