DESAFIOS DE POLÍTICA PÚBLICA
3. Inserção laboral de imigrantes
When you first booted your Raspberry Pi, you did not have to provide a username and password. However, after the initial boot, on all subsequent boots, you see a Raspbian login screen. Listing 2.1 shows how you log in to your Raspberry Pi. By default, you enter the username pi and the password raspberry. Notice that when the password is typed in, nothing appears on the screen. This is normal.
Listing 2.1 Logging In to the Raspberry Pi
Click here to view code image
Raspbian GNU/Linux 7 raspberrypi tty1 raspberrypi login: pi
Password:
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l
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.
Last login: Tue Jun 16 18:39:35 2015 pi@raspberrypi ~ $
After you have successfully completed the login process, you see the rest of the information shown in Listing 2.1. The Raspbian prompt looks like this:
pi@raspberrypi ~ $
This is also called the Linux command line. At the command line, you can enter
commands to perform various tasks. For a command to work, you must type the command in the proper case and then press the Enter key.
Did You Know?: What Is the Linux Shell?
When you enter commands at the command-line prompt, you are using a special utility called a Linux shell. The Linux shell is an interactive utility that enables you to run programs, manage files, control processes, and so on. There are several variations of the Linux shell utility. Raspbian uses the dash shell by default.
Listing 2.2 shows how you enter the whoami command. The whoami command displays the name of the user who entered the command. In this case, you can see that the user pi entered the command.
Listing 2.2 Entering a Command at the Command Line
pi@raspberrypi ~ $ whoami pi
pi@raspberrypi ~ $
You can do a lot of work at the Linux command line. Table 2.1 lists some commands that will help you as you start to learn Python programming.
Table 2.1 A Few Basic Command-Line Commands
In the following “Try It Yourself,” you will start to use some commands so you can begin to understand them better.
Try It Yourself: Log In and Issue Commands at the Command Line
In this section, you will try a few commands at the Raspbian command line. As you’ll see in the following steps, contrary to popular belief, using the command line is not hard at all:
1. Power up your Raspberry Pi. You will see a lot of startup messages scroll by the screen. These are informational, and it is a good habit to view the messages as they scroll by. Don’t worry if you don’t know what they mean. Over time, you will learn.
2. At the raspberrypi login: prompt, type pi and press the Enter key. You should now see a Password: prompt.
3. At the Password: prompt, type raspberry and press the Enter key. If you are successful, you see the pi@raspberrypi ~ $ prompt. If you are not
successful, you get the message “Login incorrect” and see the raspberry pi login: prompt again.
By the Way: Blank Passwords
If you have never logged in to a Linux command line, you might be surprised by the fact that nothing is displayed when you type in a password. Normally, in a GUI environment, you see a large dot or asterisk displayed for each character you type into the password field. However, the Linux command line displays nothing as you type a password.
4. At the pi@raspberrypi ~ $ prompt, type the command whoami and press the Enter key. You should see the word pi displayed and then, on the next line down, another pi@raspberrypi ~ $ prompt displayed.
5. Now at the prompt, type the command calendar and press the Enter key. You should see some interesting facts concerning today’s date and the next few days.
By the Way: Exploring Files and Directories
In the next few steps, you will explore files and directories. It is important that you learn how to do this so you will know how and where to store the Python programs you create in this book.
6. Type the command ls and press the Enter key. You should see a list of files and subdirectories that are located in your current location in the directory structure.
This is called your present working directory.
7. Type the command pwd and press the Enter key. This shows you the actual name of your present working directory. If you are logged in to the pi user account, the displayed present working directory is /home/pi.
8. Type mkdir py3prog and press the Enter key to create a subdirectory called py3prog. You will use this directory to store all your Python programs and work in progress.
9. To see if you created the subdirectory, type the command ls and press the Enter key. Along with the list of files and subdirectories you saw in step 6, you should now see the py3prog subdirectory.
10. To make your present working directory the newly created py3prog subdirectory, type cd py3prog and press the Enter key.
11. Make sure you are in the correct directory by typing the command pwd and pressing the Enter key. You should see the directory name
/home/pi/py3prog displayed.
12. Now go back to the pi user home directory by simply typing cd and pressing the Enter key. Make sure you made it to the home directory by typing the pwd command and pressing the Enter key. You should now see the directory name
/home/pi displayed because you are back to the home directory.
By the Way: Commands to Manage
Now you will try a few commands that will help you manage your Raspberry Pi.
13. (Warning: This next command will not work, and it is not supposed to work!) Type the command reboot and press the Enter key. You should get the message reboot: must be superuser., as shown in Listing 2.3.
Listing 2.3 Attempting a Reboot Without sudo
pi@raspberrypi ~ $ reboot reboot: must be superuser.
pi@raspberrypi ~
By the Way: Getting to Know sudo
You cannot run some commands unless you have special privileges. For example, the root user, also called the superuser, is an account that was originally set up in Linux as an all-powerful user login. Its primary purpose was to allow someone to properly administer the system. In some ways, the root account is similar to the administrator account in Microsoft Windows.
Due to security concerns, it is best to avoid logging in to the root user account. On Raspbian, you are not even allowed to log in to the root user account!
So, how do you run commands for which you need root privileges, such as installing software or rebooting your Pi? The sudo command helps you here.
sudo stands for “superuser do.” User accounts that are allowed to use sudo can perform administrative duties. The pi user account on your Raspberry Pi is, by default, granted access to the sudo command. Therefore, if you are logged in to the pi account, you can put the sudo command in front of any command that needs superuser privileges.
14. Type the command sudo reboot and press the Enter key. Your Raspberry Pi should now reboot.
15. At the raspberrypi login: prompt, type pi and press the Enter key. You should now see the Password: prompt.
16. At the Password: prompt, type raspberry and press the Enter key. If you are successful, you see the pi@raspberrypi ~ $ prompt. If you are not successful, you get the message Login incorrect and see the raspberry pi login: prompt again.
17. To change the password for the pi account from the default to something new, type in the command sudo raspi-config and press the Enter key. You should see the text-based menu you saw when you first booted your Raspberry
Pi:
Click here to view code image 1 Expand Filesystem 2 Change User Password
3 Enable Boot to Desktop/Scratch 4 Internationalisation Options 5 Enable Camera
6 Add to Rastrack 7 Overclock
8 Advanced Options 9 About raspi-config
18. Press the down-arrow key once to highlight the Change_User Password menu option. Press the Enter key.
19. You should now be at a screen that states You will now be asked to enter a new password for the pi user. Press the Enter key.
20. When you see the Enter new UNIX password: at the bottom left of your display screen, enter a new password for the pi account and press Enter. (Make it at least eight characters long and a combination of letters and numbers.) Again, as you type in the new password, you do not see it onscreen.
21. When you see the Retype new UNIX password: prompt at the bottom left of your screen, again type in your new password for the pi account at the prompt and press the Enter key. If you typed in the password correctly, you will get a screen that says Password changed successfully. In this case, press the Enter key to continue.
22. If you did not type in the password correctly, you get the message There was an error running option 2 Change User Password. In this case, repeat steps 18–21 until you succeed.
23. Back at the main Raspbian configuration (raspi-config) menu screen, press the Tab key to highlight the <Finish> selection and press the Enter key to leave the menu.
24. In the lower-left corner of the display screen, you should now see that you are back to the Raspbian prompt. At the Raspbian prompt, type sudo poweroff and press the Enter key to log out of your Raspberry Pi and gracefully power it down.
Well done! You now know several Linux command-line commands. You can log in;
move to subdirectories; list files that are in those subdirectories; and even do some management work, such as change your pi account password and reboot your system.