# Configuring Settings

By: J the Code Monkey
Posted: Dec 20, 2022 Updated: Apr 27, 2023

# What We're Doing

In this tutorial we're going to learn how to configure various settings for a Raspberry Pi (opens new window) using standard Debian (opens new window) commands. Since we'll be using standard Debian commands, the commands will be compatible with most other hardware platforms running Debian.

Instead of using the standard Debian commands to configure the settings, you can preconfigure the settings with the Raspberry Pi Imager (opens new window) by using the advanced options when installing the Raspberry Pi OS (opens new window). You also have the option to use the raspi-config (opens new window) tool to configure the settings.

If you preconfigure the settings using the Raspberry Pi Imager, you can always update them later by using either the raspi-config tool or the standard Debian commands discussed in this post.

Raspberry Pi Imager Boot Issues

If you're having issues booting your Raspberry Pi after preconfiguring the settings using the Raspberry Pi Imager, then don't preconfigure the settings. Instead you can use the raspi-config tool or the standard Debian commands to configure the settings after booting into the Raspberry Pi.

We'll be configuring the following settings:

  • Username
  • Password
  • Secure Shell (SSH)
  • WiFi
  • Time Zone
  • Keyboard Layout

We'll be using the nano text editor to edit the configuration files.

Here's how to save and exit nano:

  • Save: press Ctrl+o, confirm the filename, and press the Enter key
  • Exit: press Ctrl+x

# Assumptions

We're making the following assumptions:

# Username

There are multiple ways to update your username. We'll be updating the username by logging in as the root user. Instead of using the root user, it's also possible to create another user and log into it to update the username.

Don't Use pi for your Username

For security reasons it's recommended to not use pi as your username since it has been used in the past as the default username. Potential hackers have a list of commonly used usernames which may include the pi username.

# Enable root User

To update the username using the root user, you first need to enable it which you can do by running the following command:

Be sure to choose a secure password for the root user. You can use a password mananger like KeePass (opens new window) or Bitwarden (opens new window) to generate and store your passwords.

Disabling the root User

You can also disable the root user if you want after updating the username which we'll demonstrate below. For security reasons it's recommended to disable the root user after updating the username.

# Logout

After enabling the root user, you need to log out of the current user which you can do with the following command:

# Update Username

Now, you'll need to log in using the root user by entering root for the username and the password you just created for the root user.

After logging in as the root user, you're now ready to update the username by running the following command:

Be sure to replace:

  • <new_username> with the updated username
  • <old_username> with the username you want to update

# Update home Directory

The username has been updated, but the user's home directory will still be using the previous username. To update the home directory to reflect the updated username you need to run the following command:

Be sure to replace:

  • <new_username> with the updated username

You can now log out of the root user by running the logout command we used earlier, and log in using the updated username and the user's password.

# Disable root User

You can now disable the root user if you want, but you'll first want to make sure the updated user still has sudo privileges. You can check this by running the following command:

Be sure to replace:

  • <new_username> with the updated username

If the user still has sudo privileges, you should see the sudo group in the output.

After confirming the updated user still has sudo privileges, you can disable the root user by running the following command:

# Password

To update the password for your user you can run the following command:

You will need to enter the current password for the user. Then you will be asked to enter the updated password and to re-enter the updated password.

Be sure to choose a secure password for your user. You can again use a password mananger like KeePass (opens new window) or Bitwarden (opens new window) to generate and store your passwords.

Don't Use raspberry for your Password

It's recommended to not use raspberry as your password since it has been used in the past as the default password plus it isn't a secure password anyway.

# Hostname

Every Raspberry Pi using Raspberry Pi OS Lite (64-bit) uses the default hostname raspberrypi which isn't very helpful when you're using multiple Raspberry Pi devices that you're trying to distinguish between on your network.

hostname Restrictions

The hostname may contain lowercase letters 'a' through 'z', uppercase letters 'A' through 'Z', numbers '0' through '9', and hyphens '-' as long as the first and last characters aren't hyphens. No other symbols, punctuation characters, or white space are allowed in the hostname.

# hosts File

To update the hostname you can open the /etc/hosts file by running the following command:

Your hosts file should look something like this:

Be sure to replace:

  • <old_hostname> with the updated hostname

Then save and exit the file.

# hostname File

Next you need to open the /etc/hostname file by running the following command:

Your hostname file should look something like this:

Be sure to replace:

  • <old_hostname> with the updated hostname

Then save and exit the file.

For the changes to take effect you need to reboot your Raspberry Pi which you can do by running the following command:

After rebooting the command prompt should now display, <username>@<new_hostname>.

Where:

  • <username> is the username of the current user
  • <new_hostname> is the updated hostname

# Enable and Start SSH

Secure Shell (SSH) is a network communication protocol that enables you to connect securely to a remote computer or a server by using a text-based interface. When a secure SSH connection is established, a shell session is started, and you'll be able to manipulate the server by typing commands from your local computer.

If you want to remotely connect to your Raspberry Pi, i.e., be able to access it from your local computer, then you'll need to enable and start the SSH service on the Raspberry Pi.

# Enable SSH

To enable SSH run the following command:

# Start SSH

To start the SSH service run the following command:

You should now be able to SSH into the Raspberry Pi from your local computer.

# Configure WiFi

To configure WiFi you need to edit the wpa_supplicant.conf file.

# wpa_supplicant.conf

The wpa_supplicant.conf file should be located in the /etc/wpa_supplicant directory.

To open the wpa_supplicant.conf file you can run the following command:

After editing the file, it should look like this:

Be sure to replace:

Then save and exit the file.

For the changes to take effect you need to reboot your Raspberry Pi which you can do by running the following command:

# Unblock WiFi

If you get the following message after rebooting:

Then you can run the following command to unblock the WiFi;

Be sure to replace:

Instead of using raspi-config to unblock the WiFi which isn't a standard Debian command, you can also try installing and running urfkill.

Run the following command to install urfkill:

To unblock the WiFi using urfkill run the following command:

# Test Connection

To test the WiFi connection you can check the IP address by running the following command:

# Locale Settings

We're now going to go over how to update the time zone and keyboard layout locale settings.

# Time Zone

You can check the current time zone by running the following command:

To update the time zone you can run the following command:

Be sure to replace:

  • <area> with your own area
  • <location> with your own location

If you're unsure what your area and location are, then take a look at the list of tz database time zones (opens new window).

# Keyboard Layout

To update the keyboard layout you can edit the keyboard file which is located in the /etc/default directory.

To open the keyboard file you can run the following command:

After editing the file, it should look like this:

Be sure to replace:

  • <layout> with your preferred keyboard layout, e.g., us

Then save and exit the file.

The value for the keyboard layout is typically the two character country code (opens new window).

After updating the time zone and keyboard layout locale settings, you need to reboot your Raspberry Pi to see the changes take effect which you can do by running the following command:

# Conclusion

After following only with this tutorial, you should now know how to configure various settings for your Raspberry Pi using standard Debian commands.

Made by & for Code Monkeys 🐵