Bird
Raised Fist0
Linux CLIscripting~10 mins

SSH connection basics in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - SSH connection basics
Start SSH command
↓
Resolve hostname/IP
↓
Establish TCP connection on port 22
↓
Exchange keys and authenticate
↓
Open secure shell session
↓
User interacts with remote shell
↓
Exit session or disconnect
This flow shows how an SSH command starts, connects to a remote server securely, authenticates, and opens a shell session for user interaction.
Execution Sample
Linux CLI
ssh user@example.com
This command starts an SSH connection to the remote server example.com as user 'user'.
Execution Table
StepActionDetailsResult
1Start SSH commandUser types 'ssh user@example.com'SSH client starts
2Resolve hostnameDNS lookup for example.comIP address found
3Establish TCP connectionConnect to IP on port 22Connection established
4Exchange keys and authenticateClient and server exchange keys and user provides password or keySecure channel created and authentication success
5Open shell sessionRemote shell is readyUser can run commands
6User interactsUser types commandsCommands executed remotely
7Exit sessionUser types 'exit' or disconnectsConnection closed
💡 User ends session or connection drops, SSH closes securely
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
SSH Client StateNot startedHostname resolvedTCP connectedAuthenticatedShell openDisconnected
Key Moments - 3 Insights
Why does SSH need to resolve the hostname before connecting?
SSH must find the IP address of the hostname to know where to connect. This is shown in step 2 of the execution table.
What happens if authentication fails?
If authentication fails at step 4, the SSH connection will not open a shell session and will close. This prevents unauthorized access.
Why is port 22 important in SSH?
Port 22 is the default port SSH uses to establish the connection, as seen in step 3. Without connecting to this port, SSH cannot communicate with the server.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result after step 3?
AUser authenticated
BHostname resolved
CConnection established
DShell session opened
💡 Hint
Check the 'Result' column for step 3 in the execution table.
At which step does the user provide their password or key?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look at the 'Action' column describing authentication in the execution table.
If the hostname cannot be resolved, what will happen?
ASSH will skip to authentication
BSSH will fail to connect and stop
CSSH will open shell session anyway
DSSH will connect to port 80 instead
💡 Hint
Refer to step 2 where hostname resolution is required before connection.
Concept Snapshot
SSH connection basics:
- Use 'ssh user@hostname' to connect.
- SSH resolves hostname to IP.
- Connects on port 22.
- Exchanges keys and authenticates user.
- Opens remote shell session.
Full Transcript
SSH connection starts when the user types the ssh command with username and hostname. The client first resolves the hostname to an IP address using DNS. Then it establishes a TCP connection to the server on port 22. After connecting, the client and server exchange keys to create a secure encrypted channel and the user is asked to authenticate, usually by password or SSH key. Once authenticated, a remote shell session opens allowing the user to run commands on the server. The session continues until the user exits or disconnects, closing the connection securely.

Practice

(1/5)
1. What does the command ssh user@hostname do?
easy
A. Lists files on the remote computer.
B. Copies files from the remote computer to local.
C. Starts a secure connection to the remote computer as 'user'.
D. Deletes the user account on the remote computer.

Solution

  1. Step 1: Understand the ssh command purpose

    The ssh command is used to securely connect to another computer over a network.
  2. Step 2: Analyze the syntax ssh user@hostname

    This syntax means connect as 'user' to the computer identified by 'hostname'.
  3. Final Answer:

    Starts a secure connection to the remote computer as 'user'. -> Option C
  4. Quick Check:

    ssh user@hostname = Secure connection [OK]
Hint: ssh user@host means connect securely as user [OK]
Common Mistakes:
  • Thinking ssh copies files instead of connecting
  • Confusing ssh with file listing commands
  • Assuming ssh deletes accounts
2. Which of these is the correct syntax to connect to a remote server with ssh?
easy
A. ssh user@hostname
B. ssh -connect user hostname
C. ssh connect user@hostname
D. ssh user hostname

Solution

  1. Step 1: Recall ssh command syntax

    The correct syntax is ssh user@hostname without extra words or flags for basic connection.
  2. Step 2: Check each option

    Options A, B, and D have incorrect syntax or missing '@' sign.
  3. Final Answer:

    ssh user@hostname -> Option A
  4. Quick Check:

    Correct ssh syntax = ssh user@hostname [OK]
Hint: ssh always uses user@hostname format [OK]
Common Mistakes:
  • Adding extra words like 'connect' in command
  • Omitting '@' between user and hostname
  • Using flags incorrectly for basic ssh
3. What will happen if you run ssh alice@192.168.1.10 and the password is correct?
medium
A. You will see a list of files on your local computer.
B. The remote computer will shut down.
C. Your local files will be deleted.
D. You will be logged into the remote computer as user alice.

Solution

  1. Step 1: Understand ssh login process

    Running ssh with user and IP tries to connect and log in to that remote machine.
  2. Step 2: Check what happens on correct password

    If password is correct, you get a command prompt on the remote machine as that user.
  3. Final Answer:

    You will be logged into the remote computer as user alice. -> Option D
  4. Quick Check:

    ssh + correct password = remote login [OK]
Hint: Correct password means remote login success [OK]
Common Mistakes:
  • Thinking ssh shuts down remote machine
  • Confusing ssh with file deletion
  • Assuming ssh lists local files
4. You try to connect with ssh bob@server.com but get the error: Permission denied (publickey). What is the likely problem?
medium
A. You typed the wrong hostname.
B. Your SSH key is missing or not accepted by the server.
C. The server is turned off.
D. You forgot to install ssh on your computer.

Solution

  1. Step 1: Understand the error message

    "Permission denied (publickey)" means the server expects an SSH key for authentication but did not accept yours.
  2. Step 2: Identify cause of error

    This usually means your SSH key is missing, not loaded, or not authorized on the server.
  3. Final Answer:

    Your SSH key is missing or not accepted by the server. -> Option B
  4. Quick Check:

    Permission denied (publickey) = SSH key issue [OK]
Hint: Permission denied (publickey) means SSH key problem [OK]
Common Mistakes:
  • Assuming hostname typo causes this error
  • Thinking server power state causes this error
  • Believing ssh must be installed locally to connect
5. You want to connect to a remote server at example.com as user admin but the server uses a non-standard port 2222. Which command will connect correctly?
hard
A. ssh -p 2222 admin@example.com
B. ssh admin@example.com:2222
C. ssh admin@example.com -port 2222
D. ssh admin@2222.example.com

Solution

  1. Step 1: Recall how to specify a port in ssh

    The correct flag to specify a port is -p followed by the port number.
  2. Step 2: Analyze each option

    ssh -p 2222 admin@example.com uses -p 2222 correctly. Options A, C, and D use incorrect syntax or wrong placement.
  3. Final Answer:

    ssh -p 2222 admin@example.com -> Option A
  4. Quick Check:

    Use -p to specify port in ssh [OK]
Hint: Use ssh -p port user@host for custom ports [OK]
Common Mistakes:
  • Putting port after hostname with colon
  • Using -port instead of -p
  • Changing hostname to include port number
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard