How to Change Linux Password? How to Сhange Ubuntu Hostname?

Do you want to secure your Linux Ubuntu server? We recommend changing Ubuntu hostname and the default password given by your hosting provider. Cause the default credentials are vulnerable to online cyber attackers. When you have a unique hostname and a complex password, nobody can easily bulge into your server! So, let’s get it!

Learn how to change passwords in Linux alongside checking the server hostname through this quick tutorial. We’ll be using both terminal and GUI methods. Keep reading to learn everything!

How to change passwords in Linux (Ubuntu, CentOS, Debian)?

change passwords in Linux

As mentioned earlier, we can change the passwords of a Linux Ubuntu, CentLOS, or Debian server using the GUI or the terminal

Doing Linux change password with the Command Line is dead simple. It’s the same with any other Linux distribution. Use your terminal to execute the following steps:

Open Terminal: Launch the terminal application on your Linux system.

Run the passwd command: To change the password for a specific user, type the following command “passwd.” After executing this command, you will be prompted to enter the current password for authentication.

Enter & confirm the new password: Once authenticated, the system will ask you to enter a new password. Type the new password and press Enter. The system will ask you to retype the new password for security reasons to ensure no typos. Confirm the Ubuntu change password and press Enter.

You will receive a confirmation message that the password has been updated upon successful completion.

Understanding the Linux change password command “passwd”:

The “passwd” command allows you to manage user passwords in Linux, such as:

   -l: Locks the specified user account.

   -u: Unlocks the specified user account.

   -d: Deletes the password for the specified user, making it passwordless.

You can access the manual page for the “passwd” command by executing the “man passwd” command in your terminal.

Sometimes, the passwd command throws errors like “failed directory check” or “small password”. It can happen if the password does not contain enough different characters. So, you should consider complex combinations of different numbers and characters to set your Ubuntu password.

A note about the root Ubuntu terminal change password on an Ubuntu server/desktop:

Don’t be surprised about changing the root user account’s password. The root user in the Linux Ubuntu server doesn’t have a password for desktop usage. Even though you might not always use the root user in your Ubuntu server, a default root user profile gets created during the server installation time. This is the root user account that has admin access.

When you do the Ubuntu terminal change password, you can also change this root user account’s password. It’s mandatory because this admin user has root access. So, secure root access with your password before being late!

Now, about changing the root password, follow the same method as using the “passwd” command through the terminal. Change the root password using the following command:

sudo passwd root

You’ll have to use the sudo command to change the root password. Otherwise, you can deactivate the root account if you don’t want to use it.

How to disable your root account for Ubuntu change password?

Disabling the root account is a security measure that can prevent potential unauthorized access. Launch the terminal application to deactivate the root account and use the following command:

sudo passwd -l root

The sudo command is often used to perform administrative tasks without entirely switching to the root user. The -l option locks the specified user account. In this context, the root user account is specified, so the command is locking the root account. When the root account is locked, no one can log in using that account until it is unlocked.

How to change Ubuntu hostname?

ubuntu change hostname

Generally, the server’s hostname is set during the initial installation time. However, you can change Ubuntu hostname instead of accepting the dynamically assigned hostname. Alongside changing the password, you should also consider changing the server hostname. So, let’s explore how!

Understanding Host Names

A server’s hostname acts as a tag/label identifying a particular server among other servers or virtual machines active on the same network. Ideally, one server cannot have the same hostname as another on the same network. In Ubuntu, you can change the hostname and other server-related settings. But before that, confirm what server settings you currently have!

Check the current Ubuntu hostname & server settings

To view the current hostname of your Ubuntu system, execute the following command:



This command recognizes different classes of hostname. You get an immediate response displaying the static/dynamic hostname, icon name, chassis, machine ID, boot ID operating system details, and other server configurations.

Change Hostname Linux with “hostname” command

Before we proceed with the hostname change, you must know only root or admin users with sudo privileges can make the changes. Now, moving on with the change hostname Linux, follow the below steps:

First, check if the hostname file exists in your system or not. Use the following command:

sudo vim /etc/hostname

edit hostname

If you have the file on your server, open it through a text editor like Nano. Search for the existing preserve_hostname to change Ubuntu hostname value from false to true. Modify the file content to reflect your desired hostname. Save and close the file.

How to change the hostname in Linux without a system restart?

Changing the hostname is a common administrative task. You don't always need to reboot the system to apply such changes. You must leverage the hostname command with hostnamectl to ensure uninterrupted service availability. It allows you to make real-time adjustments to the server’s hostname and minimizes potential disruptions that a system reboot might introduce.

Ubuntu Linux Change Hostname Using “hostnamectl”

You can change the hostname without rebooting the system using the hostname command combined with the hostnamectl command. Launch your terminal application and set the new hostname using the following command:

sudo hostnamectl set-hostname [new-hostname]

You can apply the changes immediately once you replace [new-hostname] with your desired hostname. Next, execute the below command:

sudo hostname [new-hostname]

You can also use pretty, static, or transient type to define the form of your server’s hostname. Here is an example of a server with a static hostname:

sudo hostnamectl set-hostname [new-hostname] --static

By following these steps, you can change your Ubuntu server's Linux password and hostname, enhancing its security posture against potential threats. Always remember to choose strong passwords and follow best practices for system administration. To verify the change, use the hostnamectl command and print your new hostname on the terminal.

Final Verdict: It’s Time To Change Default Password Ubuntu

The above guide has given you enough insights about how to change passwords in Linux alongside changing the server’s hostname. So, implement a stronger password and a unique server hostname before your server gets compromised!