linux禁用klogin服务,Linux的登陆方式之LoginShell 和nologinShell

阅读了Linux的bash文档,总结一下

1. Linux有一些系统环境配置文件是在你登陆(刚开机要你输入密码帐号)你的Linux主机时便读取的, 他们可以弄好bash的操作环境, 比如/etc/profile, ~/.bashrc等等

2. 如标题所说Linux登陆方式有login shell和non-login shell两种,这两种登陆方式读取的系统配置文件是不同的,接下来分别解释一下什么叫login-shell,什么叫non-login shell

non-loginshell:当你开机后输入帐号密码进入Windows X(level 5)界面时,右击鼠标点打开终端(open terminal)时有一个类似windows的cmd窗口的命令行界面,这时你取得的shell叫做non-loginshell,你没有再次输入密码帐号!

login shell:当你进入纯命令行界面(level 3)时,要求你再次输入你要登陆的帐号和密码,这时你取得的shell叫做login shell

3. 接下来说一下这两种方式读取的系统配置文件有什么不同,先看一下关于bash的文档:

When  bash is invoked as an interactive login shell, or as a non-inter‐

active shell with the --login option, it first reads and executes  com‐

mands  from  the file /etc/profile, if that file exists.  After reading

that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,

in  that order, and reads and executes commands from the first one that

exists and is readable.  The --noprofile option may be  used  when  the

shell is started to inhibit this behavior.

When  a  login  shell  exits, bash reads and executes commands from the

files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.

When an interactive shell that is not a login shell  is  started,  bash

reads  and executes commands from ~/.bashrc, if that file exists.  This

may be inhibited by using the --norc option.  The --rcfile file  option

will  force  bash  to  read  and  execute commands from file instead of

~/.bashrc.

When bash is started non-interactively, to  run  a  shell  script,  for

example, it looks for the variable BASH_ENV in the environment, expands

its value if it appears there, and uses the expanded value as the  name

of  a  file to read and execute.  Bash behaves as if the following com‐

mand were executed:

if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi

but the value of the PATH variable is not used to search for  the  file

name.

来解释一下大概意思:

如果bash是login shell或者non-login shell加了--login选项登陆的。后面别管,就是login shell方式登陆的时候,那么首先会读取和执行/etc/profiles(这个是整体配置文件),接着它会去你的home里寻找有没有~/.bash_profile,~/.bash_login或者~/.profile。这些属于个人的系统配置文件(注意不同的发行版这些系统配置文件可能有可能没有!),那么如果他们同时存在的话按照哪一个来呢?注意他们的优先级是由大至小,举个例子,如果同时存在~/.bash_profile和~/.bash_login,那一切按照~/.bash_profile为准,即优先级是~/.bash_profile>~/.bash_login>~/.profile,你可以去里面看一下都是一些设置环境变量还有读取其他配置文件之类的东西。当你以login shell退出时,bash会读取~/.bash_logout和/etc/bash.bash_logout,当然前提是他们存在...

如果bash是non-login shell登陆的那么系统不会读取以上所说的配置文件,而是直接读取~/.bashrc,当然前提是这个文件存在

这个博文到此结束!文档下面还介绍了其他比如以sh或者远程rsh,ssh 等方式登陆读取的系统配置文件就不记录了,大体就这两种

PS: 解释下什么是shell,什么是bash...

shell的中文意思是壳,就像鸡蛋的外壳一样。举个例子,假设我们把鸡蛋的外壳比作shell,蛋黄比作Linux的内核,那么你要想吃到蛋黄就必须要通过shell。也就是说shell是用户和内核之间的一个接口,用户通过操作shell来对Linux内核发送指令来控制Linux的内核来分配系统硬软件资源。

而bash只是shell的一种罢了,还有很多种shell!! 因为bash比较著名...如果你是Rehat系列或者Fedora之类的 你可以输入chsh -l或者直接进入/etc/shells查看你的Linux系统上支持哪些shell, 如果你想看看你当前用的是什么shell,可以输入echo $SHELL便可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值