First Login and the Shell Prompt
The moment you log into a Linux system, you are greeted by the shell prompt. Understanding what it shows you — and how to customise it — is the first step to working confidently at the command line.
What the Prompt Tells You
A typical bash prompt looks like this:
ubuntu@ip-10-0-1-23:~$
Let’s decode each component:
ubuntu @ ip-10-0-1-23 : ~ $
│ │ │ │ │
│ │ │ │ └── $ = regular user
│ │ │ │ # = root user
│ │ │ └── Current directory
│ │ │ ~ = home directory
│ │ └── Hostname (machine name)
│ └── @ separator
└── Username (who you are logged in as)
# Common prompt examples:
ubuntu@server-01:~$ # Regular user in home directory
ubuntu@server-01:/var/log$ # Regular user in /var/log
root@server-01:/etc# # Root user in /etc
ubuntu@server-01:~/projects$ # Regular user in ~/projects
# The # symbol (root prompt) is a warning — you have full system access
# Always double-check your commands when you see #
Your First Commands After Login
# 1. Who am I?
whoami
# ubuntu
# 2. What machine am I on?
hostname
# ip-10-0-1-23
# 3. Where am I in the filesystem?
pwd
# /home/ubuntu
# 4. What's the current date and time?
date
# Tue Apr 1 10:00:00 UTC 2025
# 5. What OS and kernel am I running?
uname -a
# Linux ip-10-0-1-23 5.15.0-1057-aws ... Ubuntu
cat /etc/os-release
# NAME="Ubuntu"
# VERSION="22.04.3 LTS (Jammy Jellyfish)"
# 6. How long has this server been running?
uptime
# 10:00:00 up 42 days, 3:22, 1 user, load average: 0.08, 0.12, 0.09
# 7. What's in my home directory?
ls -la ~
# total 36
# drwxr-x--- 5 ubuntu ubuntu 4096 Apr 1 09:00 .
# drwxr-xr-x 4 root root 4096 Mar 15 08:00 ..
# -rw------- 1 ubuntu ubuntu 123 Apr 1 09:00 .bash_history
# -rw-r--r-- 1 ubuntu ubuntu 220 Mar 15 08:00 .bash_logout
# -rw-r--r-- 1 ubuntu ubuntu 3526 Mar 15 08:00 .bashrc
# -rw-r--r-- 1 ubuntu ubuntu 807 Mar 15 08:00 .profile
Understanding sudo
sudo (Super User DO) runs a command with root (administrator) privileges:
# Without sudo — permission denied for system operations
apt update
# E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
# E: Unable to acquire the dpkg frontend lock (are you root?)
# With sudo — works
sudo apt update
# [sudo] password for ubuntu: ••••••••
# Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
# Reading package lists... Done
# Run the last command with sudo (useful when you forget)
sudo !!
# Expands to: sudo apt update
# Open a root shell (be careful — all commands run as root)
sudo -i
# root@server-01:~#
# Exit the root shell
exit
# ubuntu@server-01:~$
# Check what sudo permissions you have
sudo -l
# User ubuntu may run the following commands on this server:
# (ALL : ALL) ALL ← can run any command with sudo
Sudo best practices:
- Use
sudo command— don’t open a root shell unless needed - Avoid
sudo rm -rfwithout double-checking the path - Check
sudo -lto understand your permissions on a new system
Adding a New User
# Add a new user with a home directory and bash shell
sudo adduser alice
# Adding user 'alice' ...
# New password: ••••••••
# Retype new password: ••••••••
# Full Name []: Alice Smith
# ...
# Is the information correct? [Y/n] Y
# Verify the user was created
id alice
# uid=1001(alice) gid=1001(alice) groups=1001(alice)
grep alice /etc/passwd
# alice:x:1001:1001:Alice Smith,,,:/home/alice:/bin/bash
# Add alice to the sudo group so she can use sudo
sudo usermod -aG sudo alice
# Verify alice's groups
groups alice
# alice : alice sudo
# Switch to alice's account (no password needed when using sudo)
sudo su - alice
# alice@server-01:~$
# Or log in as alice directly
su - alice
# Password: ••••••••
# Exit back to ubuntu
exit
Customising Your Prompt with PS1
PS1 (Prompt String 1) is the environment variable that defines your shell prompt:
# See your current PS1
echo $PS1
# \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
# PS1 escape sequences:
# \u — current username
# \h — hostname (short)
# \H — hostname (full)
# \w — current working directory (full path)
# \W — current directory name only (basename)
# \$ — $ for regular user, # for root
# \d — date
# \t — time (24h HH:MM:SS)
# \n — newline
# Simple custom prompt (no colours)
PS1='\u@\h:\w\$ '
# ubuntu@server-01:~$
# Coloured prompt with username (green) and directory (blue)
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# Two-line prompt (command on its own line — great for long paths)
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\$ '
# ubuntu@server-01:/very/long/path/that/goes/on/and/on
# $
# Colour reference:
# \033[00m = reset
# \033[01;30m = bold black (dark grey)
# \033[01;31m = bold red
# \033[01;32m = bold green
# \033[01;33m = bold yellow
# \033[01;34m = bold blue
# \033[01;35m = bold magenta
# \033[01;36m = bold cyan
Making Changes Permanent with .bashrc
Changes to environment variables and aliases are lost when you close the terminal — unless you save them in ~/.bashrc:
# ~/.bashrc is sourced every time you open a new interactive bash shell
# Add your customisations here
# Open .bashrc in a text editor
nano ~/.bashrc
# OR
vim ~/.bashrc
# Add these lines at the bottom:
# ── Custom Prompt ──────────────────────────────────────────────
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# ── Aliases ────────────────────────────────────────────────────
alias ll='ls -alh --color=auto'
alias la='ls -A'
alias l='ls -CF'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'
# ── History Settings ───────────────────────────────────────────
export HISTSIZE=10000 # Number of commands to remember in RAM
export HISTFILESIZE=20000 # Number of commands to save in ~/.bash_history
export HISTCONTROL=ignoredups # Don't save duplicate commands
# ── Environment Variables ──────────────────────────────────────
export EDITOR=vim
export PATH="$HOME/.local/bin:$PATH"
# Apply changes without restarting terminal
source ~/.bashrc
# OR shorthand:
. ~/.bashrc
SSH Login (Remote Servers)
When connecting to remote Linux servers, you use SSH:
# Basic SSH login
ssh username@hostname-or-ip
# Examples:
ssh ubuntu@54.123.45.67 # AWS EC2 public IP
ssh alice@192.168.1.100 # Local network
ssh ubuntu@myserver.example.com # Hostname
# SSH with a key file (common for cloud servers)
ssh -i ~/.ssh/my-key.pem ubuntu@54.123.45.67
# Permissions on the key file must be 400 or 600 (read-only by owner)
chmod 400 ~/.ssh/my-key.pem
# SSH with a different port
ssh -p 2222 ubuntu@54.123.45.67
# First time connecting: accept the host key fingerprint
# The authenticity of host '54.123.45.67' can't be established.
# ECDSA key fingerprint is SHA256:...
# Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
# Then type yes and press Enter
Key Takeaways
- The prompt format
user@hostname:directory$tells you who, where, and what privilege level -
$= regular user;#= root — always double-check commands when you see# -
sudo commandruns a single command as root — prefer this oversudo -i -
sudo adduser+sudo usermod -aG sudois the standard way to create admin users -
PS1controls the prompt appearance — customise it in~/.bashrc -
~/.bashrcis sourced for every new interactive shell — put persistent settings here - SSH with a key file (
-i keyfile.pem) is the standard way to connect to cloud servers
| ← Back to Cloud Shell (AWS & GCP) | Next → Practice Exercises |