Skip to content

Essential Linux Shell Commands and SSH Basics

Introduction to Linux Shell

User Shell Prompts

  • Regular User: $

  • Root User: #


Logging into a Remote System

Using SSH with Password

Terminal window
[user@host ~]$ ssh remoteuser@remotehost

Using SSH with Private Key

  • Ensure the private key has the correct permissions:
Terminal window
[user@host ~]$ chmod 600 privatekey.pem
  • Connect using the private key:
Terminal window
[user@host ~]$ ssh -i privatekey.pem remoteuser@remotehost

Logging Out from a Remote System

  • Use the exit command:
Terminal window
exit
  • Alternatively, press Ctrl + D.

Executing Commands in the Bash Shell

Basic Commands

  • Display current user:
Terminal window
whoami
  • Display file contents:
Terminal window
cat
  • Display the first few lines of a file:
Terminal window
head -n {number}
  • Display the last few lines of a file:
Terminal window
tail -n {number}

Date Command Options

  • Display date in RFC-2822 format:
Terminal window
date -R
  • Display date as seconds since 1970-01-01 00:00:00 UTC:
Terminal window
date -s
  • Display date in a specific format (customizable):
Terminal window
date -x

Running Multi-Line Commands

Use a backslash (\) to continue a command on the next line:

Terminal window
echo "This is a long command" \
"that spans multiple lines."

Viewing Command History

  • List previously executed commands:
Terminal window
[user@host ~]$ history
  • Re-run a command by number:
Terminal window
!number
  • Re-run the most recent command starting with a specific string:
Terminal window
!string
  • Insert the last word of the previous command:

  • Use Esc + . or Alt + .


Editing Commands on the Command Line

Useful Keyboard Shortcuts

ShortcutDescription
Ctrl + AMove to the beginning of the line
Ctrl + EMove to the end of the line
Ctrl + UClear from beginning to cursor
Ctrl + KClear from cursor to the end
Ctrl + Left ArrowMove to the beginning of the previous word
Ctrl + Right ArrowMove to the end of the next word
Ctrl + RSearch through command history