0
0
Linux CLIscripting~10 mins

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

Choose your learning style9 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.