login (在系统上开始新的登录会话)

rose1 发表于 2020-09-23 08:57
浏览次数:
在手机上阅读

在类似Unix的操作系统上,login命令在系统上开始新的登录会话。 本文档介绍了Linux版本的login。

查看英文版

目录

1 login 运行系统环境

2 login 说明

3 login 语法

4 login 例子

login 运行系统环境

Linux

login 说明

该登录程序用于与系统建立一个新的会话。通常通过响应用户终端上的“ login:”提示自动调用它。登录名可能是Shell特有的,不能作为子进程调用。从shell调用时,登录名应作为exec login 执行,这将导致用户从当前shell退出(因此将防止新登录的用户返回到调用者的会话)。尝试从任何外壳执行登录,但登录外壳会产生错误消息。

然后在适当的地方提示用户输入密码。呼应功能,以防止泄露密码。在退出登录和断开通信链接之前,仅允许少量密码失败。

如果您的帐户已启用密码时效,那么在继续操作之前,系统可能会提示您输入新密码。在继续之前,您将被迫提供旧密码和新密码;有关更多信息,请参考我们的密码。

您的用户和组ID将根据它们在/ etc / passwd文件中的值进行设置。对于价值$ HOME,$ SHELL,$ PATH,$ LOGNAME$ MAIL根据在密码输入相应的字段设置。还可以根据GECOS字段中的条目设置ulimit,umask和nice值。

在某些安装中,环境变量 $ TERM将被初始化为tty行上的终端类型,如/ etc / ttytype中所指定。

初始化脚本也可以执行;检查命令解释器的文档以获取有关初始化脚本的信息。

子系统登录通过“ * ”作为登录外壳程序的第一个字符来表示。给定的主目录将用作用户实际登录的新文件系统的根目录。

The login program is used to establish a new session with the system. It is normally invoked automatically by responding to the "login:" prompt on the user's terminal. login may be special to the shell and may not be invoked as a sub-process. When called from a shell, login should be executed as exec login which will cause the user to exit from the current shell (and thus will prevent the new logged in user to return to the session of the caller). Attempting to execute login from any shell but the login shell will produce an error message.

The user is then prompted for a password, where appropriate. Echoing is disabled to prevent revealing the password. Only a small number of password failures are permitted before login exits and the communications link is severed.

If password aging has been enabled for your account, you may be prompted for a new password before proceeding. You will be forced to provide your old password and the new password before continuing; refer to our passwd for more information.

Your user and group ID will be set according to their values in the /etc/passwd file. The value for $HOME$SHELL$PATH$LOGNAME, and $MAIL are set according to the appropriate fields in the password entry. ulimit, umask and nice values may also be set according to entries in the GECOS field.

On some installations, the environment variable $TERM will be initialized to the terminal type on your tty line, as specified in /etc/ttytype.

An initialization script may also be executed; check the documentation of your command interpreter for information on init scripts.

A subsystem login is indicated by the presence of a "*" as the first character of the login shell. The given home directory will be used as the root of a new file system which the user is actually logged into.

查看英文版

查看中文版

login 语法

login [-p] [-h host] [username] [ENV=VAR...]
login [-p] [-h host] -f username
login [-p] -r host

选件

-f 不执行身份验证;用户已预先认证。在这种情况下,用户名是必需的。
-h 此登录名的远程主机的名称。
-p 保护环境。
-r 为rlogin执行自动登录协议。

配置

/etc/login.defs中的以下配置变量更改了此工具的行为:

名称 类型 描述
CONSOLE_GROUPS string 在控制台上登录时要添加到用户补充组中的组列表(由CONSOLE设置确定)。默认为无。

请谨慎使用-即使未在控制台上登录,用户也有可能获得对这些组的永久访问权。
DEFAULT_HOME boolean 指示如果我们无法cd到主目录,是否允许登录。默认为no。如果设置为yes,则如果无法cd到用户的主目录,则用户将登录到根(/)目录。

如果设置,它将在常规用户登录时用于定义PATH环境变量。该值是用冒号分隔的路径列表(例如/ bin:/ usr / bin),并且可以在PATH =之前。默认值为PATH = / bin:/ usr / bin。
ENV_PATH string 如果设置,它将用于在超级用户登录时定义PATH环境变量。该值是用冒号分隔的路径列表(例如/ sbin:/ bin:/ usr / sbin:/ usr / bin),可以为在PATH =之前。默认值为PATH = / sbin:/ bin:/ usr / sbin:/ usr / bin。
ENV_SUPATH string 如果设置,它将用于在超级用户登录时定义PATH环境变量。该值是用冒号分隔的路径列表(例如/ sbin:/ bin:/ usr / sbin:/ usr / bin),可以为在PATH =之前。默认值为PATH = / sbin:/ bin:/ usr / sbin:/ usr / bin。
ERASECHAR number 终端擦除字符(010 =退格键,0177 = 删除键)。

该值可以以八进制值作为前缀“ 0 ” ,或以十六进制值作为前缀“ 0x ” 。
FAIL_DELAY number 登录失败后延迟秒数,之后才允许再次尝试。
FAKE_SHELL string 如果设置,则login将执行此shell而不是/ etc / passwd中指定的用户的shell 。
HUSHLOGIN_FILE string 如果定义,此文件可以禁止在登录过程中所有常见的颤动。如果指定了完整路径名,则在文件中找到用户名或外壳程序时,将启用静音模式。如果不是完整的路径名,那么如果文件位于用户的主目录中,则将启用静默模式。
KILLCHAR number 终端杀死字符(025 = ^ U)。

该值可以以八进制值作为前缀“ 0 ”,或以十六进制值作为前缀“ 0x ”。
LOGIN_RETRIES number 密码错误的情况下最大的登录重试次数。

这很可能会被PAM覆盖,因为默认的pam_unix模块具有自己的内置3次重试。但是,如果您使用的是不强制使用PAM_MAXTRIES的身份验证模块,这是一个安全的备用方法。
LOGIN_TIMEOUT number 登录的最长时间(以秒为单位)。
LOG_OK_LOGINS boolean 启用成功登录的日志记录。
LOG_UNKFAIL_ENAB boolean 记录登录失败时,启用显示未知的用户名。

注意!如果用户输入密码而不是登录名,则登录未知的用户名可能是安全问题,因为这样会记录错字。
TTYGROUPTTYPERM string 终端权限:登录tty将由TTYGROUP组拥有,并且权限将设置为TTYPERM。

默认情况下,终端的所有权设置为用户的主要组,权限设置为0600。

TTYGROUP可以是组的名称,也可以是数字组标识符。

如果您有一个写程序,该写程序是对拥有端子的特殊组的“ setgid”,则将TTYGROUP定义为组号,并将TTYPERM定义为0620。否则,将TTYGROUP注释掉,然后将TTYPERM分配给622600。
TTYTYPE_FILE string 如果定义,则文件将tty行映射到TERM环境参数。文件的每一行均采用“ vt100 tty01 ”之类的格式。
USERGROUPS_ENAB boolean 如果设置为yes,则如果userdel不包含任何成员,则userdel将删除该用户的组,并且useradd将创建(默认情况下)具有用户名的组。

文件

/var/run/utmp 当前登录会话列表。
/var/log/wtmp 以前的登录会话列表。
/etc/passwd 用户帐户信息。
/etc/shadow 安全的用户帐户信息。
/etc/motd 一天文件的系统消息。
/etc/nologin 防止非root用户登录。
/etc/ttytype 终端类型列表。
$HOME/.hushlogin 禁止打印系统消息。
/etc/login.defs 阴影密码套件配置。

-r、 -h-f选项仅在 root调用登录时使用。

login [-p] [-h host] [username] [ENV=VAR...]
login [-p] [-h host] -f username
login [-p] -r host

Options

-f Do not perform authentication; user is preauthenticated. In that case, username is mandatory.
-h Name of the remote host for this login.
-p Preserve environment.
-r Perform autologin protocol for rlogin.

Configuration

The following configuration variables in /etc/login.defs change the behavior of this tool:

name type description
CONSOLE_GROUPS string List of groups to add to the user's supplementary groups set when logging in on the console (as determined by the CONSOLE setting). Default is none.

Use with caution - it is possible for users to gain permanent access to these groups, even when not logged in on the console.
DEFAULT_HOME boolean Indicate if login is allowed if we can't cd to the home directory. Default is no.

If set to yes, the user will login in the root (/) directory if it is not possible to cd to the user's home directory.
ENV_PATH string If set, it will be used to define the PATH environment variable when a regular user login. The value is a colon separated list of paths (for example /bin:/usr/bin) and can be preceded by PATH=. The default value is PATH=/bin:/usr/bin.
ENV_SUPATH string If set, it will be used to define the PATH environment variable when the superuser logs in. The value is a colon separated list of paths (for example /sbin:/bin:/usr/sbin:/usr/bin) and can be preceded by PATH=. The default value is PATH=/sbin:/bin:/usr/sbin:/usr/bin.
ERASECHAR number Terminal Erase character (010 = backspace, 0177 = Del).

The value can be prefixed "0" for an octal value, or "0x" for an hexadecimal value.
FAIL_DELAY number Delay in seconds before being allowed another attempt after a login failure.
FAKE_SHELL string If set, login will execute this shell instead of the users' shell specified in /etc/passwd.
HUSHLOGIN_FILE string If defined, this file can inhibit all the usual chatter during the login sequence. If a full pathname is specified, then hushed mode will be enabled if the user's name or shell are found in the file. If not a full pathname, then hushed mode will be enabled if the file exists in the user's home directory.
KILLCHAR number Terminal KILL character (025 = ^U).

The value can be prefixed "0" for an octal value, or "0x" for an hexadecimal value.
LOGIN_RETRIES number Maximum number of login retries in case of bad password.

This will most likely be overridden by PAM, since the default pam_unix module has its own built in of 3 retries. However, this is a safe fallback in case you are using an authentication module that does not enforce PAM_MAXTRIES.
LOGIN_TIMEOUT number Max time in seconds for login.
LOG_OK_LOGINS boolean Enable logging of successful logins.
LOG_UNKFAIL_ENAB boolean Enable display of unknown usernames when login failures are recorded.

Note! Logging unknown usernames may be a security issue if a user enters their password instead of their login name, as the typo would then be logged.
TTYGROUPTTYPERM string The terminal permissions: the login tty will be owned by the TTYGROUP group, and the permissions will be set to TTYPERM.

By default, the ownership of the terminal is set to the user's primary group and the permissions are set to 0600.

TTYGROUP can be either the name of a group or a numeric group identifier.

If you have a write program which is "setgid" to a special group which owns the terminals, define TTYGROUP to the group number and TTYPERM to 0620. Otherwise, leave TTYGROUP commented out and assign TTYPERM to either 622 or 600.
TTYTYPE_FILE string If defined, file which maps the tty line to the TERM environment parameter. Each line of the file is in a format such as "vt100 tty01".
USERGROUPS_ENAB boolean If set to yes, userdel will remove the user's group if it contains no more members, and useradd will create (by default) a group with the name of the user.

Files

/var/run/utmp List of current login sessions.
/var/log/wtmp List of previous login sessions.
/etc/passwd User account information.
/etc/shadow Secure user account information.
/etc/motd System message of the day file.
/etc/nologin Prevent non-root users from logging in.
/etc/ttytype List of terminal types.
$HOME/.hushlogin Suppress printing of system messages.
/etc/login.defs Shadow password suite configuration.

The -r-h and -f options are only used when login is invoked by root.

查看英文版

查看中文版

login 例子

login computerhope.com

尝试登录到主机尝试登录到主机computerhope.com。

login computerhope.com

Attempts to log in to the host computerhope.com.

查看英文版

查看中文版

其他命令行

link | ldd | last | ln | ls | lsmod | lpstat | losetup | lprm | lpr | lpq | lp | lpc | locate | logname | lpadmin |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条