如果没有安全密码(secure password),您的数据将很容易受到攻击。容易猜到或先前泄露的密码使黑客的工作变得容易——毕竟,如果“password123”是您的密码,破解用户帐户并不难。(breach a user account)这就是为什么定期更改密码很重要的原因,即使在像Linux(Linux)这样更安全的操作系统上也是如此。
值得庆幸的是,在Linux(Linux)中更改密码是一个简单的过程。您可以在本地或远程从终端更改您的密码(或其他用户的密码),或设置到期日期以强制其他用户在下次登录时自行更改。以下是您在更改用户密码时需要执行的操作任何Linux发行版。

为什么要定期更改 Linux 密码(Why You Should Change Your Linux Password Regularly)
虽然基于 Linux 的操作系统比典型的Windows安装提供了更高的安全性,但这并不意味着它对黑客来说是万无一失的。某人破坏您的 PC 的最简单方法之一是通过松懈的安全性,易于破解的密码位于列表顶部。
不幸的是,你也应该预料到时间对你不利。我们中的许多人对多个帐户使用相同的密码。例如,如果您的电子邮件密码被泄露(email password is compromised),并且您使用相同的密码登录 Linux PC,那么您的 PC(以及您保存的所有数据)将面临风险。

这就是为什么考虑定期更改 Linux 中的所有密码很重要的原因,包括您在 Linux 上的帐户(Linux)密码(Linux)。一个好的密码由许多字母(大写和小写)、数字和特殊字符组成。它还要求密码长度合适(至少 8 个字符,如果不是更多)。
如果您难以想出一个可以记住的密码,您可以使用密码管理器(use a password manager)来帮助您生成和记住它。您将无法使用它来填写登录屏幕,但如果您使用的是 KeePass 之类的密码管理器(password manager like KeePass),您可以使用移动应用程序快速调用密码。
但是,创建一个您能记住的密码可能是最好的(也是最简单的)。字典单词不在此菜单中,但在可能的情况下,您应该尝试使用我们上面概述的步骤创建一个其他人不可能知道的令人难忘的密码。
如何在 Linux 中更改密码(How to Change Your Password in Linux)
虽然您应该能够使用发行版的桌面环境更改密码,但这些步骤会有很大差异。如果您使用的是无头版本的Linux(没有GUI),则根本无法使用GUI更改密码。
这就是为什么在Linux(Linux)中更改密码的最佳和最快方法是使用终端,而不管您使用 的是哪种Linux 发行版。(Linux distribution)
- 打开一个新的终端窗口或与您的Linux PC 或服务器建立远程SSH连接。如果您正在远程连接,则需要输入现有密码以进行身份验证(如果您还没有)。

- 登录(远程或本地)后,键入passwd开始更改密码的过程。passwd命令对几乎所有基于 Unix 的操作系统都很常见,包括Linux和 macOS。

- 要使用passwd更改您的Linux密码,请先输入您现有的密码,然后输入两次以确认您的新密码,选择Enter以移动到每个新行。您将无法看到您的输入,因此如果您在输入过程中输入错误,请随时选择键盘上的Enter键。(Enter)这将导致passwd失败,因为它将无法匹配新密码或使用前一个密码进行身份验证。

- 如果该过程成功,passwd将在终端中返回一条成功消息。如果不是(例如,如果您输入错误的密码),则需要重复该过程。

在 Linux 中更改其他用户帐户密码(Changing Other User Account Passwords in Linux)
如果您在 Linux PC 或服务器上具有超级用户或 root 访问权限(例如,如果您是系统管理员),您可以更改其他本地用户的密码。例如,如果有人忘记了密码,您可能想要这样做。
- 为此,请在本地打开终端窗口或使用SSH远程连接。终端或连接打开后,键入su或sudo su以切换到 root 用户帐户。您需要提供正确的 root 用户密码才能执行此操作。

- 使用sudo su或su切换到 root后,您可以开始更改其他用户的密码。为此,请键入passwd user,将user替换为您要更改的帐户的用户名。如果您不确定用户名是什么,请键入cat /etc/passwd。每行中的第一个单词(例如ubuntu)是您 PC 上的用户名。

- 您需要输入两次新密码,在每行后选择Enter键。(Enter )

- 如果您正确输入密码,passwd将返回成功消息。如果您输入的密码不正确(例如,如果新密码不匹配),您需要重复这些步骤才能成功更改密码。

如何使用 Sudo 在 Linux 中更改 Root 密码(How to Change the Root Password in Linux using Sudo)
为了帮助保护您的系统,许多Linux发行版通过将某些访问权限隐藏在 root(超级用户)帐户后面来限制普通用户帐户。当您使用sudo su或su等命令提升终端以授予 root 访问权限时,您需要输入正确的 root 密码。
- 要更改 root 密码,您需要打开终端窗口或使用SSH远程连接。在终端中,键入sudo su或su以切换到超级用户帐户,然后选择键盘上的Enter键。

- 使用 root 访问权限,键入passwd并选择Enter键。您需要提供两次新密码,在每行后选择Enter 。

- 如果命令成功,passwd会在终端输出成功信息。如果失败,您将需要重复这些步骤以完成该过程。

在 Linux 中设置密码到期日期(Setting a Password Expiry Date in Linux)
通过在Linux(Linux) PC上设置密码的内置到期日期,您无需担心定期手动运行passwd命令。(passwd)当密码过期时,您的 PC 将指示您自动更改密码。
- 要在Linux(Linux)中设置密码到期日期,请打开终端窗口或使用SSH远程连接。在终端中,输入chage -M 100 user并选择Enter键,将100替换为下次到期前的天数,将user替换为您的用户名。如果您想为其他用户帐户设置到期日期,请键入sudo chage -M 100 user代替,将占位符详细信息替换为您自己的。

- 设置详细信息后,您可以通过键入chage -l user(chage -l user )并选择Enter来检查到期日期,将user替换为您要检查的用户名。

保护 Linux 系统(Securing a Linux System)
Linux是众所周知的最安全的操作系统之一,但如果没有适当的安全密码,您的 PC 就会容易受到攻击。还有其他方法可以进一步保护您的系统,例如维护安全的本地网络(maintaining a secure local network)和扫描文件以查找(scanning your files for viruses)可能感染其他 PC 的病毒。
您还可以考虑使用安全的网络浏览器来保持在线安全,特别是如果您考虑使用 VPN(using a VPN)来掩盖您的 IP 地址。努力保护您的在线隐私和安全(protect your online privacy and security)不会阻止黑客攻击,但会增加另一层防御。
How to Change Password in Linux
Without a secure password, your data is vulnerable. Easy to guess or previously leaked passwords make a hacker’s job easy—after all, it isn’t hard to breach a user account if “password123” is your password. That’s why it’s important to change your password regularly, even on a more secure operating system like Linux.
Thankfully, it’s an easy process to change your password in Linux. You can change your password (or other user’s passwords) from the terminal locally or remotely, or set expiration dates to force other users to change it themselves when they next sign in. Here’s what you’ll need to do to change a user password in any Linux distribution.

Why You Should Change Your Linux Password Regularly
While a Linux-based operating system offers greater security than a typical Windows installation, that doesn’t mean it’s infallible to hackers. One of the easiest ways for someone to breach your PC is through lax security, with easy-to-crack passwords at the top of the list.
Unfortunately, you should also expect that time is against you. Many of us use the same passwords for multiple accounts. If your email password is compromised, for instance, and you use the same password to sign into your Linux PC, then you’re putting your PC (and all of your saved data) at risk.

That’s why it’s important to consider changing all your passwords in Linux on a regular basis, including your account passwords on Linux. A good password consists of a number of letters (both upper and lower case), numbers, and special characters. It also requires the password to be of suitable length (at least 8 characters, if not more).
If you’re struggling to come up with a password you can remember, you can use a password manager to help you generate and remember it. You won’t be able to use this to fill out the login screen, but if you’re using a password manager like KeePass, you can quickly recall the password using the mobile app.
However, it’s probably best (and easiest) to create a password that you can remember. Dictionary words are off the menu for this one, but where possible, you should attempt to create a memorable password that no-one else could possibly know using the steps we’ve outlined above.
How to Change Your Password in Linux
While you should be able to change passwords using your distro’s desktop environment, those steps will vary significantly. If you’re using a headless version of Linux (without a GUI), you won’t be able to use a GUI to change your password at all.
That’s why the best and fastest way to change your password in Linux is to use the terminal, regardless of the Linux distribution you’re using.
- Open a new terminal window or make a remote SSH connection to your Linux PC or server. If you’re connecting remotely, you’ll need to type in your existing password to authenticate if you haven’t already.

- Once you’ve signed in (either remotely or locally), type passwd to begin the process of changing your password. The passwd command is common to almost all Unix-based operating systems, including Linux and macOS.

- To change your Linux password using passwd, type in your existing password first, then confirm your new password by entering it twice, selecting Enter to move to each new line. You won’t be able to see your input, so if you make a mistake during the typing process, select the Enter key on your keyboard at any point. This will cause passwd to fail, as it won’t be able to match the new passwords or authenticate using the previous one.

- If the process is successful, passwd will return a success message in the terminal. If it isn’t (for example, if you mistyped your password), you’ll need to repeat the process.

Changing Other User Account Passwords in Linux
If you have superuser or root access on your Linux PC or server (for instance, if you’re a system administrator), you can change the passwords of other local users. You may want to do this if someone has forgotten their password, for instance.
- To do this, open a terminal window locally or connect remotely using SSH. Once the terminal or connection is open, type su or sudo su to switch to the root user account. You’ll need to provide the correct root user password to be able to do this.

- Once you’ve switched to root using sudo su or su, you can begin to change another user’s password. To do this, type passwd user, replacing user with the username of the account you wish to change. If you’re unsure what the username is, type cat /etc/passwd instead. The first word in each line (for example, ubuntu) is a username on your PC.

- You’ll need to type in the new password twice, selecting the Enter key after each line.

- If you type the passwords correctly, passwd will return a success message. If you type the passwords incorrectly (eg. if the new passwords don’t match), you’ll need to repeat these steps to successfully change it.

How to Change the Root Password in Linux using Sudo
To help protect your system, many Linux distributions restrict normal user accounts by hiding certain access behind the root (superuser) account. When you elevate your terminal using commands like sudo su or su to grant root access, you’ll need to type the correct root password.
- To change the root password, you’ll need to open a terminal window or connect remotely using SSH. In the terminal, type sudo su or su to switch to the superuser account, then select the Enter key on your keyboard.

- With root access, type passwd and select the Enter key. You’ll need to provide a new password twice, selecting Enter after each line.

- If the command is successful, passwd will output a success message in the terminal. If it fails, you’ll need to repeat these steps to complete the process.

Setting a Password Expiry Date in Linux
By setting a built-in expiry date for passwords on your Linux PC, you don’t need to worry about manually running the passwd command on a regular basis. When the password expires, your PC will instruct you to change your password automatically.
- To set a password expiry date in Linux, open a terminal window or connect remotely using SSH. In the terminal, type chage -M 100 user and select the Enter key, replacing 100 with the number of days before the next expiration and user with your username. If you want to set expiration dates for other user accounts, type sudo chage -M 100 user instead, replacing the placeholder details with your own.

- With the details set, you can check the expiration date by typing chage -l user and selecting Enter, replacing user with the username you wish to check.

Securing a Linux System
Linux is well known as one of the most secure operating systems available, but without a secure password in place, you’re leaving your PC vulnerable to attack. There are other ways you can secure your system further, such as maintaining a secure local network and scanning your files for viruses that could infect other PCs.
You could also think about using a secure web browser to stay safe online, especially if you consider using a VPN to mask your IP address. Making efforts to protect your online privacy and security won’t stop hacking attempts, but it will add another layer of defense against it.