Login and Logout in Linux

Source: Internet
Author: User

Login process

Login is the first process you face when working on a Linux system. It is correct for using a terminal or using Linux over the network. But the login process itself is not what you see on the terminal. What you see is actually getty (get TeleTYpe terminal, which in the early days of the Computer meant to get the tape terminal, now it can be understood as opening the terminal). It is started by init (via/etc/inittab) when the login process is started.

The complete start chain is init-> getty-> login-> passwd-> shell-> applications. This is technically different in actual implementation. For example, sometimes login and passwd are in a program, but the above chain is very typical in UNIX.

So why are we doing this? Why can't I write a program to handle all the work. Is it inappropriate for a getty program to process both login and passwd?

Let a program do only one simple thing and then link a lot of simple work to create this complex runtime environment, which is the key to ensuring UNIX stability, this is also a key design criterion when you create your system. (See the KISS criterion, classic in UNIX)

Debian6 provides six terminals by default (Ctrl + Alt + F1 ~ F6, because F7 and F8 are used to open the graphic interface rather than as a terminal), but in fact the kernel is 64 terminals by default, so where are other terminals? If you are on a Linux virtual machine, you can access tty10 or even tty12 (using Ctrl + Alt + F *), but you do not have more function keys, we will discuss how to access other terminals later.

Logout process

The logout process is very simple. It needs to terminate the task or shell opened by the login process. Note that it is not just a shell but all things to close.

If I use long to log on as a user, I will get a shell. If I use ls, I will get the ls result and then I log out. Therefore, the logout shell sends a signal to the parent process to notify it that the shell has been terminated. But the shell's parent process is login and login has stopped running (logout terminals login and shell). So who will get the shell return value? It is init to accept the return value of logout. After getty, login, and logout are disabled, init re-opens a getty to wait for the input.

Let's take a look at the fun stuff:

-Rwxr-xr-x 1 root 975488 Dec 29 2012/bin/bash

-Rwxr-xr-x 1 root 49008 May 25 2012/bin/login

-Rwxr-xr-x 2 root 32040 Dec 11 2012/sbin/getty

-Rwsr-xr-x 1 root 51096 May 25 2012/usr/bin/passwd

We can see that all except passwd have the rwxr-xr-x permission, and all of them can be executed by any user, while passwd is the-rwsr-xr-x permission, this s is the identifier of the setuid, which allows common users to run programs or commands that can only run with the root account as the root user, therefore, passwd runs under the root permission (even for a common user ). With this, we can reduce security risks.

Login configuration

When you log on using login, you not only open a shell but also configure your runtime Environment (runtime env). If this configuration is system-level in/etc, if it is in your personal home directory, it is a personal configuration.

The approximate Division is as follows:

/Etc/profile-for all users and all shells

/Etc/bash. bashrc-bash configuration for all users

~ /. Bashrc-your personal bash Configuration

In actual use, we need to place the configuration in different configuration files according to different requirements. For example, if a configuration is useful to all users using this system, we need to put it under/etc/profile.

Su

When talking about user logon, let's talk about root permissions. Using the su command (su-), you not only switch user permissions, but also create a new login session, so what you get is not only a root, but also a completely new runtime environment, which is very sensitive to security issues. Therefore, you must pay attention to using the root permission. Of course, you can also use sudo to temporarily grant root permissions to your users. This is a good method for desktop users, but for large systems, be sure to give sudo permissions to users. It is best not to give them!

Exit vs logout

If you use login to log on to the system, you can choose exit or logout to exit the system. Is there a difference between the two? For most systems, there is no difference between the two, but there is a little difference between the two: logout will be executed ~ /. Bash_logout (if any), and exit will only be used to exit the job without executing ~ /. Bash_logout. There is no other difference.

======================================

This article is written by me and Daniel. If you have any objection, please point it out and discuss it.

Recommended reading:

How to Implement logout/suspension in Linux)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.