如何在 Linux 中跳出当前用户名和密码 (linux 跳出当前用户名和密码)

How to Switch User and Password in Linux

Linux is an open source operating system known for its robustness, security features, and flexibility. It offers a wide range of tools and functionalities for managing user accounts and passwords, including switching users and passwords. In this article, we will explore how to switch user and password in Linux.

1. Switching Users in Linux

Switching user in Linux allows you to log in to a different account on the same machine without logging out of your current account. This is useful when you want to access another user’s files, run a command as another user, or test the access levels of a particular user. There are two ways to switch user in Linux: using the su (substitute user) command or the sudo (superuser do) command.

Using the su Command

The su command allows you to switch to another user account by entering the desired username and password. You can use the su command to switch to any user account on the system, including the root user account, which has full administrative privileges.

To switch to another user account using the su command, open the terminal and type the following command:

su username

Replace “username” with the username of the account you want to switch to. You will be prompted to enter the password for that user account.

After entering the correct password, you will be logged in as the specified user. You can now perform tasks as that user, such as accessing files or running commands.

To switch back to your original account, simply type the exit command or press CTRL-D. This will terminate the current user session and return you to the previous user session.

Using the Sudo Command

The sudo command is another way to switch user in Linux, but it grants temporary administrative privileges to the user instead of completely changing to a different account.

To switch to another user account using the sudo command, open the terminal and type the following command:

sudo su username

Replace “username” with the username of the account you want to switch to. You will be prompted to enter the password for your current user account.

After entering the correct password, you will be granted temporary administrative privileges as the specified user. You can now perform tasks as that user, such as accessing files or running commands. When you are finished, simply type the exit command or press CTRL-D to terminate the current user session and return to your original account.

2. Changing Passwords in Linux

Changing your password periodically ensures the security of your Linux system. It is also advisable to change your password if you suspect that someone else has access to your account password. There are different tools and methods to change passwords in Linux, depending on the Linux distribution and the user account type.

Using the passwd Command

The passwd command is the most common tool for changing passwords in Linux. It allows a user to change their own password or the password of another user.

To change your own password using the passwd command, open the terminal and type the following command:

passwd

You will be prompted to enter your current password and then the new password twice. Note that Linux passwords are case-sensitive and should be at least eight characters long, including letters, numbers, and special characters.

To change another user’s password using the passwd command, open the terminal and type the following command:

sudo passwd username

Replace “username” with the username of the account whose password you want to change. You will be prompted to enter the password for your current user account and then the new password twice for the specified user.

Using the Usermod Command

The usermod command is another tool for changing passwords in Linux. It allows you to modify user account information, including resetting the password.

To reset a user’s password using the usermod command, open the terminal and type the following command:

sudo usermod –password “$(openssl passwd -1 newpassword)” username

Replace “newpassword” with the desired password and “username” with the username of the account whose password you want to change.

Conclusion

In this article, we have explored how to switch user and password in Linux using different tools and methods. Switching user in Linux allows you to log in to a different account on the same machine without logging out of your current account, while changing passwords ensures the security of your Linux system. By knowing how to switch user and password in Linux, you can maximize the benefits and flexibility of this powerful operating system.


数据运维技术 » 如何在 Linux 中跳出当前用户名和密码 (linux 跳出当前用户名和密码)