Introduction to the Raspberry Pi
Working as the 'root' user
By default, the root user is disabled, but we need to use it with our SFTP client later in the project. An SFTP client is a program that allows us to transfer files between two computers using the same secure protocol used in SSH.
When we are working on the Raspberry Pi using the terminal emulator and SSH, we can simple switch to the root user with the “sudo” command:
$ sudo su
This means that the root (or “super user”, hence “su”) user is available, but is only accessible via the “sudo” command. It is not enabled for remote access, such as SSH or SFTP.
Once you become “super user” with “sudo”, you can work as if you were logged in as “root”, and access parts of the file system that are only permitted to the root user, or edit files owned by root.
To exit the super user and go back to the normal “pi” user, type:
Let’s enable external login to the root account to make our life a bit easier.
First, login to your Raspberry Pi as “pi”:
$ ssh [email protected]
Then, change into the super user:
[email protected]:~ $ sudo su
And finally, use the nano text editor to edit the sshd_config file:
[email protected]:/home/pi# nano /etc/ssh/sshd_config
Scroll down the sshd_config file to find the PermitRootLogin directive. Its argument should be “yes”. Remove the “#” to un-comment it.
Type Control-X to exit and save the changes in the file.
Next, restart the SSH daemon so that the changes become effective:
[email protected]:/home/pi# /etc/init.d/ssh restart
You are now almost ready to be able to login to your Raspberry Pi using the root user. The last thing to do is to set a password for the root user.
Do this with the “passwd” command:
[email protected]:/home/pi# passwd root
Retype new password:
passwd: password updated successfully
The utility will ask you for the new password for the root user. I use “raspberry”, since I have no security concerns. If I was working to create a security-sensitive application, I would only enable the root user during development, and disable it for production.
Time to test your “new” root user. Exit super user, then exit the pi user, and then login to your Raspberry Pi using “root”:
[email protected]:/home/pi# exit
[email protected]:~ $ exit
Connection to raspberrypi-zero.local closed.
Peters-iMac:~ peter$ ssh [email protected]
[email protected]'s password:
Linux raspberrypi-zero.local 4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
In the command line session above, I have marked in bold the “root” user in my new SSH command. As you can see, I was able to login to my Raspberry Pi using “root”.
Good work so far.
You can log out from root.
Your Raspberry Pi is now ready for development, but there’s one more critical set of operations I’d like to show you: backing up and restoring your Raspberry Pi SD Card. This will save you countless hours and frustration when things go wrong, and give you a reliable way to recover from disaster.
"Raspberry Pi Getting Started" series
Ready for some serious learning?
Start right now with Raspberry Pi Full Stack - Raspbian
This is our most popular Raspberry Pi course & eBook.
This course is a hands-on project designed to teach you how to build an Internet-of-Things application based on the world’s most popular embedded computer.
You will learn how to build this application from the ground up, and gain experience and knowledge with technologies such as...
- The Linux operating system and the command line,
- The Python programming language,
- The Raspberry Pi General Purpose Input Output pins (GPIOs),
- The Nginx web server,
- The Flask Python web application microframework,
- JQuery and CSS for creating user interfaces,
- How to deal with timezones,
- How to create charts with Plotly and Google Charts,
- How to do datalogging with Google Sheet,
- How to create applets with IFTTT,
- How to secure your application with SSL.
Jump to another article in this series.