Linux 的 root 是否可以命令行一句,就能改变已存在的用户登陆 shell?

2018-05-27 16:42:03 +08:00
 pppguest3962

网上的方式,都是去 vi /etc/passwd,找到那个用户,然后去修改它的 shell 是 bash、还是 /sbin/nologin,我是 root 的话,是否简便的命令行修改方式,重新定义指定用户的登录环境呢?

3316 次点击
所在节点    Linux
12 条回复
ngg0707
2018-05-27 16:52:35 +08:00
用 sed ?
tan9le
2018-05-27 16:54:52 +08:00
usermod -s 默认 shell 路径 用户名
param
2018-05-27 17:03:22 +08:00
chsh -s /bin/bash
不知道在网上是怎么找的
param
2018-05-27 17:03:39 +08:00
不知道你是怎么在网上找的
EricXuu
2018-05-27 17:04:55 +08:00
chsh 这是基础吧,兄弟
pppguest3962
2018-05-27 17:52:27 +08:00
@ngg0707,感谢,好办法,我并非系统管理员,也不是靠 linux 吃饭,不熟练 sed,希望尽早能掌握。。。

@tan9le 正确答案,感谢~

@EricXuu,你确认这命令能改其它用户的 shell ?
eccstartup
2018-05-27 17:57:29 +08:00
su - aaa - c chsh ...... 这种呢?
lcdtyph
2018-05-27 18:11:25 +08:00
@pppguest3962 chsh 有个可选的参数是 username
chsh -s path/to/shell user
katsusan
2018-05-27 18:12:26 +08:00
root 下可以直接 chsh +用户名来修改

➜ ~ chsh mldonkey
Changing the login shell for mldonkey
Enter the new value, or press ENTER for the default
Login Shell [/bin/false]:
pppguest3962
2018-05-27 23:13:32 +08:00
@katsusan
@EricXuu
@param
是我自己疏忽,现在才有条件测试,chsh 确实可行
而自己又没测试过,确实不知道。
bao3
2018-05-28 05:21:55 +08:00
楼主先看一下鸟哥吧
justdoit123
2018-05-30 18:47:16 +08:00
话说,chsh、自己手动改都不能 check 对应的 shell 是否可用,这会有个大坑:
如果 shell 不可用,然后已经退出了远超登录。那么恭喜,你再也登录不上这台 vps 了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/458141

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX