Skip to content

Practice: Your First Linux Session

Module
Your First Linux Session
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.4 LTS (VM, VirtualBox 7.2.18) and 24.04.5 LTS (lab system), GNU Bash 5.2.21
On this page

Module B04 asks for one thing before its first lesson: a terminal with a Bash prompt. You have one evening at the computer you share at home to make sure you have it. A friend who took this course before you sends advice for that evening:

Before you follow any guide, check who you are. If a terminal hangs, don’t wait: close the VM’s window and click OK. It’s faster. And put the VM away properly at the end.

The first and last sentences are good advice. The middle one can damage the VM’s disk. You also know that someone at home will need you for a few minutes while the VM is running, and the screen will be in plain view.

This practice puts all four lessons of the module to work in one sitting: the desktop, the terminal and the console, your account and root, and the ways out of a stuck command or a stuck VM. You work without reading along, and you write down what you see.

  • The four lessons of this module, from Desktop and session basics (B03.1) to Shutdown, restart, and session recovery (B03.4).
  • The VM rootvolt-lab, with the user learner, from module B02. Start it and wait for the login screen.
  • A lab notebook: a text file on your host, not inside the VM, as in the B02 practice. The VM is off at the end of this practice, and you still need your notes.

Close the lessons and try each goal on your own first. Look back only after you have tried, and note in your notebook what you had to look up.

Every command in this practice only reads. Type each one exactly as the lessons did and press Enter. Nothing on the system changes, and you power off and restart only from Ubuntu’s menu.

Reach these six goals, in order. Each one is an outcome; deciding how to reach it is part of the practice.

  1. You have opened Files and Settings without the dock. While you were away from the computer, nobody could use your session, and when you came back, it was as you left it. You have also seen what logging out does to the same windows.
  2. You have a terminal window, you can read its prompt part by part, and you can explain in two sentences which program draws the window and which one reads the commands you type.
  3. You have reached the text console of the VM, logged in there, and come back to the desktop. You can say why tty gives a different kind of name there than in a window.
  4. Before you follow any guide, you know which account you work as and whether it may administer the system. You have seen one action refused for that account, and you have run that one read-only action as root.
  5. You have got a working prompt back three times: from a command that runs too long, from a command that waits for you to type, and after closing a terminal window with a command still running.
  6. You have decided what to answer your friend about “close the VM’s window and click OK”, and what you would choose instead. You have restarted the VM once from Ubuntu’s menu, and at the end, the VM is off, shut down by Ubuntu itself.

When you are done, your lab notebook holds the following. Every item is something you saw on your own screen or a short answer in your own words.

Goal 1

  • After unlocking: Files and Settings are still open, where you left them.
  • After logging out and back in: neither window is open.
  • One sentence on which of the two you choose when you step away, and why.

Goal 2

  • The prompt learner@rootvolt:~$, with what each of its four parts means.
  • What tty printed in the window: a /dev/pts/ name. The number depends on how many windows are open.
  • What ps printed: a bash line on the same pts name. The PIDs vary.
  • Your two sentences: which program draws the window, and which program reads your commands.

Goal 3

  • The console’s first line, ending in rootvolt tty3, and rootvolt login: below it.
  • What tty printed there: /dev/tty3.
  • The keys that took you to the console and back.
  • One sentence on why the window gave a pts name and the console a tty name.

Goal 4

  • What whoami printed: learner.
  • From id: uid=1000(learner), and the name sudo among the groups. The group numbers and the full list may differ on your installation.
  • The refusal for ls /root, ending in Permission denied.
  • The sudo password line, [sudo] password for learner:, and what ls listed in /root after you typed your password: in the tested VM, one name, snap.
  • One task you would use sudo for, and one situation in which you would not.

Goal 5

  • ^C, then the prompt, after the long command.
  • The prompt with no ^C after the command that waited for your input.
  • The warning Close this terminal? before the window closed, then a new window with a prompt.

Goal 6

  • In VirtualBox’s Close Virtual Machine dialog: which of the three options was selected when it opened, and whether Restore current snapshot ‘clean-install’ was ticked.
  • Your answer to your friend, in two or three sentences: what OK does with that selection, and what you do instead when a terminal hangs and when the whole desktop is stuck.
  • The Restart dialog, then the login screen.
  • The Power Off dialog, then a VM that turned off without a VirtualBox dialog.

Open a hint only when you are stuck on that goal.

Hint for goal 1

One key opens the overview, and typing there searches at once. Locking has a shortcut: that key plus one letter. Logging out sits behind the power button in the system menu, and its dialog has a countdown: read it before you walk away from it.

Hint for goal 2

The terminal has a shortcut with three keys; on a Windows or Linux host, use the left Ctrl key. For the two sentences, ask which program does not understand commands at all. ps lists the processes on the terminal where you run it: which program is in the list, and which one is missing?

Hint for goal 3

In a VM, Ctrl+Alt and a function key may be caught by the host. VirtualBox has its own key for this, and the console you want is number 3. Nothing appears while you type the password there. To come back, first end your login on the console, then use the same key with the number of the desktop’s console.

Hint for goal 4

Two commands answer “who am I?”: one gives the name, the other the numbers and the groups. Root’s home directory is the place your account may not look into. When sudo asks for a password, read whose password it names.

Hint for goal 5

Lesson B03.4 used two commands that keep the prompt away: one counts seconds, the other waits for what you type. One key stops a command; another tells it that the input has ended, and it works at the start of a line. For the closed window, a new one opens with the same shortcut as in goal 2.

Hint for goal 6

Open the dialog your friend means and read it, then leave it without choosing anything. Ask what each option does to Ubuntu: does Ubuntu get to shut down by itself? For a hanging terminal, ask whether the VM is the problem at all. For a stuck desktop, goal 3 gave you a way to check whether Ubuntu is still running underneath.

Solution

Goal 1: step away safely

  1. Log in: click learner, type your password, and press Enter.
  2. Press Super, type files, and click Files. Press Super again, type settings, and click Settings. Neither click is in the dock.
  3. Before you leave the computer, press Super+L, or click the padlock button in the system menu. The lock screen shows the time and date, and Click or press a key to unlock.
  4. When you come back, press a key, type your password, and press Enter. Files and Settings are where you left them: locking hid the session, and the session kept running.
  5. Open the system menu, click the power button, and choose Log Out…. The dialog Log Out learner counts down; click Log Out. Log in again. No app window is open: logging out ended the session and closed its apps.

Your sentence could read: “When I step away, I lock with Super+L, because the session and its windows keep running and only my password opens them. Logging out closes every app, and anything I had not saved may be lost.”

Goal 2: the terminal and the prompt

Press Ctrl+Alt+T. In the tested VM, the window held one line:

Screen
learner@rootvolt:~$
Part Means
learner The user you are logged in as
rootvolt The computer’s name
~ The directory you are in: your home directory
$ Bash is waiting for a command

Run tty, then ps. In the tested VM:

Screen
learner@rootvolt:~$ tty
/dev/pts/0
Screen
learner@rootvolt:~$ ps
PID TTY TIME CMD
3034 pts/0 00:00:00 bash
3097 pts/0 00:00:00 ps

bash is on the same terminal device that tty named, and GNOME Terminal is not in the list: it does not run on the terminal device, it holds the other end and draws the window.

Your two sentences could read: “GNOME Terminal, a terminal emulator, draws the window, passes my keys on, and shows the text that comes back; it does not understand commands. Bash, the shell, reads the commands I type and starts the programs they name.”

Goal 3: the text console

  1. Press Host+F3: the right Ctrl key and F3, on a Windows or Linux host. VirtualBox sends Ctrl+Alt+F3 to the VM. The desktop disappears; the first line names the release, the computer, and tty3, and rootvolt login: waits below it.
  2. Type learner, press Enter, type your password at Password:, and press Enter. Nothing appears while you type the password. After the welcome text, the same prompt appears.
  3. Run tty. In the tested VM:
Screen
learner@rootvolt:~$ tty
/dev/tty3
  1. Type exit and press Enter: rootvolt login: appears again. Then press Host+F2 to bring the desktop back.

Why the names differ: a terminal window’s device is a pseudoterminal, which the kernel creates for a program, here GNOME Terminal, so its name is under /dev/pts/. The text console is a terminal that the kernel provides directly on the screen and keyboard, with a terminal device of its own, /dev/tty3. Both are TTYs; in both, Bash reads your commands.

Goal 4: who you are, and one action as root

In a terminal window, run whoami, then id. In the tested VM:

Screen
learner@rootvolt:~$ whoami
learner
Screen
learner@rootvolt:~$ id
uid=1000(learner) gid=1000(learner) groups=1000(learner),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),114(lpadmin)

You are learner, a regular user, with user ID 1000. The group sudo means that this account may run commands as root with sudo.

Ask for root’s home directory:

Screen
learner@rootvolt:~$ ls /root
ls: cannot open directory '/root': Permission denied

The program ls ran, and the system refused the action for your account. Nothing is broken. Now run the same read-only command as root, with sudo ls /root. sudo asks for your password, the one you log in with, and nothing appears as you type it. In the tested VM:

Screen
learner@rootvolt:~$ sudo ls /root
[sudo] password for learner:
snap

Only that one command ran as root; the prompt after it is learner@rootvolt:~$ again.

Your answer could read: “I use sudo for administration, such as installing software or changing a system setting, and only for a command I can read. I do not use it for my own files, or as a reflex after an error: I read the message first, because most errors are not about permission.”

Goal 5: three ways back to the prompt

  1. Run sleep 300 and press Ctrl+C. On the course’s lab system:
Screen (lab system)
learner@rootvolt:~$ sleep 300
^C
learner@rootvolt:~$
  1. Run cat, type a line, and press Enter: cat prints it back and waits for the next one. Press Ctrl+D at the start of the next line. cat sees that the input has ended and finishes normally, so no ^C appears. On the lab system, without a typed line:
Screen (lab system)
learner@rootvolt:~$ cat
learner@rootvolt:~$
  1. Run sleep 300 again and click the window’s ×. GNOME Terminal asks Close this terminal?: “There is still a process running in this terminal. Closing the terminal will kill it.” Here it is only sleep, so click Close Terminal. Press Ctrl+Alt+T: a new window, a new Bash, and a new prompt. What was in the closed window is gone.

Goal 6: the friend’s advice, and the end of the evening

Click the × of the VM’s window on the host. Read the Close Virtual Machine dialog, then click Cancel, not OK. In the tested VM, Power off the machine was already selected when the dialog opened, and Restore current snapshot ‘clean-install’ was unticked. Leave it unticked: ticked, it also returns the VM to that snapshot, and the changes since then are lost.

With that selection, OK is “equivalent to pulling the power plug on a real computer without shutting it down properly”, as the VirtualBox manual says, and it “can potentially cause data loss or an inconsistent state of the guest system on disk”. Your answer could read:

“Clicking OK out of habit pulls the VM’s power cable, so I read the selection first. A hanging terminal is not a reason to close the VM: Ctrl+C stops a running command, and Ctrl+D ends the input of one that waits for me. If the whole desktop is stuck, I press Host+F3; if I can log in on the console, Ubuntu is running: I log out with exit, press Host+F2, and give the desktop a minute. If it is still stuck, I choose Send the shutdown signal, which asks Ubuntu to shut down by itself. Power off the machine is for a guest that does not respond to that either.”

Then end the evening from Ubuntu’s menu:

  1. Open the system menu, click the power button, and choose Restart…. The Restart dialog says “The system will restart automatically in 60 seconds.” Click Restart. The VM turns off, starts again, and shows the login screen. Log in.
  2. Open the system menu again, click the power button, and choose Power Off…. The Power Off dialog says “The system will power off automatically in 60 seconds.” Click Power Off.

Ubuntu ends your session, closes the programs still running, and finishes its work on the disk before the power goes off. No VirtualBox dialog was needed.

Answer each question without looking back, then open the answer.

1. You meant to lock the screen, but the dialog Log Out learner is open and counting down. What happens if you walk away now, and what do you do instead?

Answer

When the countdown ends, you are logged out: doing nothing is not the same as cancelling. Every app in the session closes, and anything you had not saved may be lost. Click Cancel, then lock with Super+L or the padlock button.

2. Why does tty print a pts name in a terminal window and a tty name on the text console?

Answer

A terminal window’s device is a pseudoterminal: a terminal device that the kernel creates for a program, here the terminal emulator GNOME Terminal, not for a real screen and keyboard. Its name is under /dev/pts/. The text console is a terminal that the kernel provides directly on the screen and keyboard, so its device is the kernel’s own, such as /dev/tty3.

3. A guide says “type this in the shell”, and you type the command into the overview’s search box. Why does nothing run?

Answer

That box belongs to GNOME Shell, the program that draws the desktop, which is not a shell despite its name. It searches for apps and settings; it does not run commands. Type the command at the Bash prompt in a terminal.

4. Why does Ubuntu’s root account have no usable password, and whose password does sudo ask for?

Answer

Ubuntu’s installer locks root’s password and sets up sudo for the user created during the installation, so nobody can log in as root with a password. Attackers know a system “has an account named root and will try that first”; with the password locked, there is none to guess. sudo asks for your password, as [sudo] password for learner: says.

5. You see > instead of your prompt. What is Bash waiting for, and how do you get your prompt back?

Answer

Bash waits for the rest of the line: usually a quote that was opened and never closed. > is Bash’s secondary prompt. Press Ctrl+C to abandon the whole line; nothing runs, and the normal prompt returns.

6. Why is Power off the machine not the normal way to stop the VM?

Answer

It is like pulling the power plug of a real computer: Ubuntu does not get to shut down. Programs are not closed and Ubuntu does not finish its work on the disk, which can cause data loss or an inconsistent state of the guest system on disk. The normal way is Power Off… in Ubuntu’s menu. Power off the machine is for a guest that cannot shut down by itself.

  • Super and typing open any app; Super+L locks a session that keeps running, and Log Out… ends it and closes its apps.
  • GNOME Terminal draws the window and Bash reads your commands. tty names the terminal device: /dev/pts/N in a window, /dev/tty3 on the text console, which Host+F3 opens and Host+F2 leaves.
  • whoami and id tell you that you are learner, in the group sudo. sudo runs one command as root after your own password, and only for administration you can read.
  • Ctrl+C stops a running command, Ctrl+D ends the input of one that waits, and Ctrl+Alt+T replaces a closed window.
  • Restart and power off from Ubuntu’s menu. In VirtualBox’s Close dialog, read the selection before OK: Power off the machine pulls the power cable.

Next, module B04 starts with Command anatomy (B04.1), in the terminal you now know how to open, read, and recover.

All sources are the ones the module’s lessons were written from, for Ubuntu 24.04 LTS with GNOME 46 and VirtualBox 7.2.