The virtual machine system keeps cycling through the login interface and cannot log in.

Link: Reprint

The Ubunt system of the virtual machine keeps going back and forth in the login interface and cannot log in.
1. Introduction:
Early in the morning, I excitedly opened the virtual machine, but I couldn't log in. There is no problem in determining the password at this time. After searching on Baidu online, I found out that it was caused by environment variables. Suddenly I remembered that I just installed the golang environment yesterday and modified the /etc/environment file of environment variables. Then the problem is obvious, change it back.

About building the golang environment:
https://blog.csdn.net/ljfphp/article/details/81044500

2. Solution process
1. Switch from the graphical interface to the command line

This varies depending on the operating system. It is recommended to try ctrl+alt+ F1~F6. After trying for a long time, the blogger found that he was:

ctrl+alt+F4
2. New question

  改成命令行之后,进行登录。此时我们发现能够登录成功。但是在我们进行操作,比如ls或者vim或者sudo的时候,报错:

//Even the sudo command cannot be used.
The command could not be located because '/usr/bin/sudo' is not included in the PATH environment variable.
This is the cause of the problem: the environment variable PATH is wrong. It seems that PATH was indeed manipulated when modifying the /etc/environment file, so the easiest way to solve the problem is to restore /etc/environment to the state before modification.

3. The role of path

Linux has PATH. Those who have configured JDK under Windows must have noticed that Windows also has path. What is this PATH used for? Let’s explain it below:

  当我们在命令行(Linux下的terminal或者tty1~6,windows下的cmd中)输入一个命令时,实际上执行的是一个程序。比如使用 ls 命令,实际上是运行 ls 这个程序,它的功能是列出当前目录下的内容。但是,默认情况下搜寻要运行的程序时,仅是在当前目录下寻找的。而我们平时使用的命令不论在哪个目录下都能执行,难道是每个目录下都有这些命令的拷贝?当然不是,这样对空间的浪费太严重了。


  现在操作系统采取的普遍做法是,通过PATH变量指定命令存放的位置。一旦使用某个命令时,按照PATH中制定目录的顺序去搜寻指令对应的程序。所以正常情况下,使用echo $PATH查看环境变量PATH的内容如下:

The semicolon ":" represents the separator character that separates each directory.

Due to the PATH error, when I use the command, the system cannot normally search for it in the directory where the command is stored, so it will prompt: Command not found.

4. Solution

  很人性化的是,系统会提示我们要使用的指令存放的正确位置,比如使用clear时提示的:Command ‘clear’ is available in ‘/usr/bin/clear’。clear命令是存放在’/usr/bin’目录下的。

To edit /etc/environment, the command normally used is: sudo vim /etc/environment

  现在,系统找不到sudo 命令,也找不到vim命令,所以只能人工指定它们的绝对路径了。sudo 和 vim 都是存放在’/usr/bin’目录下的,所以sudo和vim的绝对路径分别是:/usr/bin/sudo /usr/bin/vim

Therefore, the command to use to edit /etc/environment should be written as follows: /usr/bin/sudo /usr/bin/vim /etc/environment

  只需要把自己之前添加的内容删除掉就可以了(最好是能修改成正确的,搞不定也要至少恢复原状吧),然后保存重启系统。

Restart under normal conditions: sudo reboot

Of course it doesn’t work now, you have to use /usr/bin/sudo /sbin/reboot

3. Modification process
1. Original environment variables

PATH=“/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games” export PATH=$
PATH :/usr/local/go/bin
export GOPATH=/var/go
It can be seen here that adding PATH is directly using: + path. The second line here is a redefined PATH, which is probably here. question, so change it to:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/ go/bin”
export GOPATH=/var/go
After changing it, restart the system and try it, and find that you can log in normally. (PS: I’m here for this reason. Everyone operates according to their actual situation. If it doesn’t work, restore the environment variables to their original state first, and then modify them)

4. About the Linux environment variable directory.
I saw on the Internet that some people modified /etc/profile and some people modified /etc/environment. So what is the difference?

answer:

•/etc/profile - This file sets environment information for each user of the system. When the user logs in for the first time, this file is executed and collects shell settings from the configuration file in the /etc/profile.d directory; •/etc/environment - the second file used by the operating system when logging in. The system sets the environment variables of the environment file before reading your own profile; •/etc/bashrc - for each running bash shell The user executes this file. When the bash shell is opened, the file is read; •~/.profile - Each user can use this file to enter shell information dedicated to their own use. When the user logs in, this file only Execute once! By default, it sets some environment variables and executes the user's .bashrc file; •~/.bashrc - This file contains bash information specific to your bash shell, which is executed when logging in and every time a new shell is opened. The file is read;
as can be seen here:

/etc/profile 是所有用户的环境变量(用户环境)/etc/enviroment是系统的环境变量(系统环境)
  也就是说咱们修改 /etc/environment的话,相当于修改的系统环境,不管是哪个用户登进来,都是使用相同的环境变量。而修改/etc/profile的话,针对的是用户的环境变量

  OK,总之算是解决了登录问题。碰到的问题千千万,记录一下,希望能帮到需要她的人,也给自己做个笔记。

Guess you like

Origin blog.csdn.net/qq_45972323/article/details/132746183
Recommended