3种方法改变Linux的默认shell |
您所在的位置:网站首页 › linux怎么把root改成别的用户 › 3种方法改变Linux的默认shell |
shell是Unix或GNU/Linux等操作系统中的命令解释器,shell是一个接受和解释命令的程序;Linux 上有多种 shell,例如 bash、sh、ksh、zsh、fish 和许多其他鲜为人知的 shell。它为计算机用户提供了 Unix/GNU Linux 系统的接口,以便用户可以使用一些输入数据运行不同的命令或实用程序/工具。当 shell 执行完程序后,它会在屏幕上向用户发送一个输出,这是标准输出设备。因此,它被称为“命令解释器”。 Bash ( /bin/bash ) 是大多数Linux 系统上的流行 shell,它通常是用户帐户的默认 shell。 在 Linux 中更改用户的 shell 有几个原因,包括: 使用nologin shell阻止或禁用Linux 中的正常用户登录。 在将用户命令发送到 shell 执行之前,使用 shell 包装脚本或程序登录用户命令。在这里,您将 shell 包装器指定为用户的登录 shell。 满足用户的需求(想要使用特定的 shell),尤其是那些具有管理权限的用户。下面来看一下Linux系统中所有可用的shell。 [root@sharplee creatfile]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash 下面是改变shell需要牢记的一些点: 一个用户能够改变他们自己的shell为任何shell,但是前提这个shell要在/etc/shells中要有。 仅仅只有root用户有权限更改shell在Linux中的/etc/shell文件中找不到的shell。 如果一个用户是被限制登录的,这个用户的shell只有root用户有权限更改。1,使用usermod修改 usermod是一个工具用于修改用户账号的信息,这些信息存储在“/etc/passwd”中,下面我们通过 -s 或者 --shell选项来改变用户的shell。 [sharplee@sharplee creatfile]# grep sharplee /etc/passwd [sharplee@sharplee creatfile]# sudo usermod --shell /bin/sh sharplee [sharplee@sharplee creatfile]# grep sharplee /etc/passwd 下面来检验一下用户的shell是否被修改了。 2,使用chsh命令进行修改 chsh 是一个命令行实用程序,使用 -s 或 –shell 选项更改登录 shell,如下所示。 [sharplee@sharplee creatfile]# grep sharplee /etc/passwd[sharplee@sharplee creatfile]# sudo chsh --shell /bin/bash sharplee[sharplee@sharplee creatfile]# grep sharplee /etc/passwd
下面通过重新登陆一下sharplee用户来看一下shell改变了没。
3,通过修改/etc/passwd文件实现 下面通过文本编辑工具,来修改/etc/passwd文件,实现改变用户的shell。 [root@sharplee creatfile]# vi /etc/passwd or [root@sharplee creatfile]# nano /etc/passwd 总结:通过变更shell能够实现用户无法登录,改变shell为/sbin/nologin即可实现,还可以通过更改其它shell来增强bash能够执行更多的命令交互。
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |