Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 4: Linux Advanced Commands

AWS Cloud

4.11 Remote access: ssh and scp

Friends, sending files from your laptop to the server and bringing logs back from the server – this is daily work. ssh for login, scp for copying and rsync for smart sync.

# Offline example using the scratch configuration from the workshop lab
ssh -G -F "$ssh_lab/client.conf" workshop-ssh
# After verifying an authorized lab host, account and fingerprint:
ssh -n -F "$ssh_lab/client.conf" workshop-ssh 'id -un; pwd' 

An SSH alias selects a client profile. This example uses a reserved documentation address. Keep it in a scratch file and preview it offline.

Host workshop-ssh
    HostName 192.0.2.42
    User workshop
    Port 2222
    IdentityFile "/path/to/your/training-key"
    IdentitiesOnly yes
    StrictHostKeyChecking ask

Use the scratch ssh -G preview to verify those settings. For actual transfer, first confirm the approved host key, account, and destination folder as the lab illustrates.

Ravindra Bagale's Tip

A remote scp operand includes a host, colon, and path, such as workshop-ssh:training/worksheet.txt. A host-like word without a colon is a local filename in that form. The SSH profile can provide the identity setting.

Lab

खालील workshop lab मध्ये scratch SSH profile चा offline preview पहा. मंजूर lab host आणि fingerprint तपासल्यावरच scratch directory मध्ये एक worksheet upload करा, पुन्हा download करा आणि ती मूळ प्रतीशी जुळते का ते पहा.

Remote access evidence

Record the authorized destination, expected account, and host verification method before you connect. Transfer only the expected worksheet and compare the returned bytes. Keep the exact scratch path for cleanup and keep private identity material out of the report.

Start by identifying both ends of the connection

The Mauli workshop has a worksheet on a student's laptop and a training server where a coworker will review it. The student needs to sign in, place a copy in a designated training folder, and confirm that it arrived with the expected content. A separate question arises if the workshop's live website also runs on the server. Being able to transfer a file does not by itself authorize changing that site. Start with the exact machine, account, and destination assigned to the exercise.

Secure Shell, or SSH, is a protocol for an encrypted connection and a family of tools that use it. An SSH client on your laptop initiates a connection to an SSH server process, usually called sshd, on the other machine. Once the parties have negotiated the connection and completed the required authentication, the server can open a shell or execute a command under an approved account. The familiar ssh tool makes this connection. scp uses SSH for file transfer and uses SFTP by default in current OpenSSH. You can use the same host identity and user authorization while performing a different operation.

Two separate identities matter. The client needs to recognize the server it intended to contact. The server uses a host key to prove its identity during the SSH handshake. The server must also decide whether the user is allowed to authenticate. A user key pair can meet that second requirement when the server authorizes its public part for the account. These roles are distinct. Your local private key proves control of your user identity to the server. The server's host key identifies the destination to the client. A key offered in one role cannot replace the decision made in the other.

For most EC2 Linux images, record the actual host name or approved address, the operating system username, the private identity path on your own client, and the port. Amazon Linux commonly uses ec2-user and Ubuntu images commonly use ubuntu, but the image publisher or administrator can specify a different account. The key file must correspond to a key authorized for that account. The console or administrator can establish the approved path to the instance, which might be a private route or a managed connection rather than a public endpoint. All examples in this lesson use fictitious names and a disposable artifact. Use an actual remote host only if it is a lab host you are authorized to access.

A typical SSH connection has several observable stages. A name lookup or address selection occurs first. A TCP connection reaches the configured service port. The client and server then agree on the encrypted channel and the client checks the host identity. The user authenticates. Finally the server launches a session, command, or file transfer subsystem if that action is permitted. A useful troubleshooting note identifies the earliest stage that did not succeed. That choice directs the next check and avoids confusing a missing network route with an incorrect login account.

Verify the server identity before authenticating

During the first connection to a new name and port, OpenSSH can show a fingerprint for an unfamiliar host key. A fingerprint is a short digest derived from the public host key. Compare the offered algorithm and fingerprint to a value from a trustworthy independent source, such as the lab owner or an authenticated administrative console. For an EC2 instance, AWS documents ways to obtain the instance's host fingerprint where the needed host-key information is available. Check the actual instance identity in that channel. Receiving a key from the same unverified connection is insufficient to establish who owns the host.

When you accept a verified host key, the client generally records it in a known_hosts file. On later connections it compares the offered identity to that recorded information. Different names, ports, or aliases can affect how records are looked up. Treat an unexpected changed-key warning as a reason to pause. A replacement machine or key rotation can be legitimate, but verify the new key through the owner before updating any entry. Clearing the entire file or disabling the verification removes evidence needed to distinguish a legitimate change from a wrong endpoint. The lab below uses one separate trust file and retains host verification.

A user key pair has a public part that the system can authorize and a private part the user keeps. In a public-key authentication exchange, the client proves possession of a usable private key without sending the private key file to the server. If the file has a passphrase, the prompt normally asks to unlock the local key. That is different from supplying a remote account password. A key agent can support the local unlock workflow when configured. Do not copy the private key to the web server, upload it with site files, or put it in a shared report. The server needs only the approved public authorization for the account.

OpenSSH can refuse a private identity file whose mode is too permissive. Inspect the permissions of the exact local key and use your platform's approved way to restrict them to the owner. AWS's Unix example for a PEM key uses owner read permission, represented as chmod 400 on that exact private identity path. Avoid applying the same command recursively to a directory of unrelated files. A private key should also have a suitable owner and storage location. A correct local mode does not make the corresponding public key authorized on every server. Those checks belong to separate sides of the session.

SSH clients support agents, configuration files and several identity sources. -i selects an identity path for that command, while a Host block can supply an IdentityFile. IdentitiesOnly yes limits authentication to configured identities instead of offering additional arbitrary agent identities. Some OpenSSH identity directives can accumulate rather than follow a simple one-setting rule, so inspect the effective configuration. For this lab only one identity is intended. Agent forwarding is unnecessary. Keeping the agent local avoids granting a remote session use of that agent as part of this exercise.

Preview a client configuration without connecting

Use Bash on your own client machine, with OpenSSH tools and the ordinary file utilities present. The first stage is offline. It creates a scratch client config with a documentation-only IPv4 address and a placeholder account and key. The address block containing 192.0.2.42 is assigned for documentation. It does not name the workshop or a target to contact. The -G command prints the evaluated client configuration and exits without connecting. Read only the relevant fields instead of publishing your complete connection configuration.

ssh_lab=$(mktemp -d /tmp/mauli-ssh.XXXXXXXX) || exit 1
printf 'Lab directory: %s\n' "$ssh_lab"
cat > "$ssh_lab/client.conf" <<CONFIG
Host workshop-ssh
    HostName 192.0.2.42
    User workshop
    Port 2222
    IdentityFile "/path/to/your/training-key"
    IdentitiesOnly yes
    ForwardAgent no
    ConnectTimeout 5
    StrictHostKeyChecking ask
    UserKnownHostsFile "$ssh_lab/known_hosts"
CONFIG
chmod 600 "$ssh_lab/client.conf"
ssh -G -F "$ssh_lab/client.conf" workshop-ssh | awk '
  $1 == "hostname" || $1 == "user" || $1 == "port" || $1 == "identityfile" { print }
'
user workshop
hostname 192.0.2.42
port 2222
identityfile /path/to/your/training-key

The scratch directory line is omitted in the expected display, and the property order can vary. The -F option selects the separate client config rather than your normal user file. Host defines a new alias in that file. HostName selects the actual destination, and the user and port come from the intended server. The identity path remains local. The explicit trust file holds only records added for this exercise, and the ask setting prompts about unfamiliar identities when confirmation is needed. A configuration may still use the client's trusted global host keys, depending on its settings. The printed settings verify how the proposed alias is understood and do not prove that any connection, login or transfer works.

For an actual training connection, edit the scratch file with the lab owner's approved host name or address, account, port and local identity path. Keep normal server verification enabled and set the necessary approved client options. Some managed pathways use a jump host or a session broker, which are outside this direct lab. If your access requires one of those, use the approved profile and remain within its scope. Do not replace the unknown values with guessed usernames or addresses. Rerun the same configuration preview to confirm you are about to address the correct training endpoint.

Verify the account and connection before writing a file

The remaining live steps require an approved training account and an independently verified server identity. Skip them if you only have the documentation profile. Prepare an ordinary account whose home is writable and whose server actions are limited to this exercise. This lab assumes standard ssh and SFTP access to the same training account and home area. It does not require root or permission to write in a web root. First ask the remote shell to print the effective account and its working directory.

ssh -n -F "$ssh_lab/client.conf" workshop-ssh 'id -un; pwd'
workshop
/home/workshop

The output shows one possible account and directory. The -n option prevents this one-shot SSH command from reading input from the calling shell. This is useful when a script or loop has its own input to preserve. Compare real output with the authorized configuration before proceeding. If the client prompts to accept a new host key, verify its fingerprint and algorithm independently before accepting it. If an expected local key is encrypted, follow its ordinary unlock prompt. The words between single quotes are sent for remote execution because the calling shell treats them as literal arguments. The semicolon inside the command separates two operations on the remote side. A shell prompt displayed after starting an interactive SSH session similarly belongs to the remote host, and its path and command results refer to that host.

The exit status from an ordinary successful remote command can pass through the ssh client, while a connection or login failure is reported by the client. A connection-level ssh error commonly uses status 255. If a script depends on remote execution, capture the status as well as its text. The two-command demonstration above reads easy-to-recognize outputs. Do not use the success of the second command to claim that an earlier one necessarily worked in a longer shell list. Use explicit conditional checks and verification in automation.

If authentication is rejected, identify the stage and read the diagnostic. A message such as Permission denied (publickey) usually means the server reached user authentication and did not accept the available method or identity. Verify the approved username and selected local identity and have the administrator check authorization on the server when needed. A warning about private key permissions can occur before the key is used. By contrast, a connection timeout or refusal asks for network and service checks around the expected destination and port. An unfamiliar or changed host key asks for independent identity verification. Repeating a login with weaker checks would change the evidence without resolving those questions.

Copy one known artifact and verify its contents

scp reads its operands in source-then-destination order. The colon in workshop-ssh:directory/file.txt separates the SSH host from the remote path. Without it the operand is generally interpreted as a local filesystem path. An explicit local path beginning with a slash or ./ can clarify that a colon in a local filename belongs to the name. With a client configuration, both ssh and scp can use the alias and its approved port, account, identity and host verification settings. If you specify a port as a command flag, ssh uses lowercase -p and scp uses uppercase -P. The latter tool uses lowercase -p for preserving selected file metadata.

Choose a unique remote scratch name derived from the generated local directory. The fixed prefix identifies only the exercise and the random suffix is checked to contain letters and digits. This matters because the constructed remote command will be parsed by a shell on the host. A local quote pair does not automatically protect arbitrary expansions through a remote shell. In this exercise the allowed characters make the one remote path literal and predictable. Use the following only after the login output confirmed the authorized training account.

unset remote_dir
ssh_suffix=${ssh_lab##*.}
case "$ssh_suffix" in
  ''|*[!A-Za-z0-9]*) printf 'Unexpected scratch suffix. Stop here.\n' >&2 ;;
  *)
    remote_dir="mauli-transfer-$ssh_suffix"
    if ssh -n -F "$ssh_lab/client.conf" workshop-ssh "mkdir -m 700 -- '$remote_dir'"; then
      printf 'Created training directory: %s\n' "$remote_dir"
    else
      printf 'Creation failed. Do not copy into that path.\n' >&2
      unset remote_dir
    fi
    ;;
esac

The relative directory is made under the remote session's normal starting directory, which was verified in the previous command. The -m 700 mode limits access to the owner under normal mode-bit rules. We intentionally do not use mkdir -p. A collision with an existing folder should cause the creation step to fail so the lab does not write into someone else's artifacts. Continue only when you saw the explicit created-directory message. The second step will use the same exact name under the account's file-transfer home.

printf '%s\n' 'Mauli workshop handover' 'Use the approved worksheets.' > "$ssh_lab/worksheet.txt"
if scp -F "$ssh_lab/client.conf" "$ssh_lab/worksheet.txt" "workshop-ssh:$remote_dir/worksheet.txt" \
  && scp -F "$ssh_lab/client.conf" "workshop-ssh:$remote_dir/worksheet.txt" "$ssh_lab/returned.txt" \
  && cmp "$ssh_lab/worksheet.txt" "$ssh_lab/returned.txt"; then
  printf 'Uploaded and downloaded worksheet matches locally\n'
  cat "$ssh_lab/returned.txt"
else
  printf 'Transfer or comparison failed. Read the diagnostic before retrying.\n' >&2
fi
Uploaded and downloaded worksheet matches locally
Mauli workshop handover
Use the approved worksheets.

Both scp commands may print progress or ask to unlock the authorized private identity. Check each invocation's status and diagnostic before treating the output as complete. The first reads the local source and writes the explicit remote filename. The second reads that remote filename and writes a different local copy, leaving the source available for comparison. The cmp result is independent of the progress display and verifies that the expected bytes are the ones you brought back. A returned copy from a previous run could otherwise look valid, which is why using a freshly generated directory matters.

If you have to retain provenance rather than only confirm equality, record the destination account and resolved path along with the artifact name and a check value, such as a SHA-256 digest from the intended source. In a team workflow the authoritative digest can travel through an authenticated channel. The current exercise compares content immediately after a round trip. It does not prove that a deployed application can read the uploaded file. That would need an application-specific check and appropriate deployment authorization. A transfer connection provides transport and remote account access for the file operation it actually performed.

Choose a destination and a copy mechanism deliberately

To send a report, name its source on the machine where the client runs and its destination on the authorized endpoint. If you issue scp from a remote shell already opened on the server, the word local now describes that server for this new scp process. The student's laptop path is not automatically accessible there. A reliable workflow runs the client from the laptop when the laptop owns the source or target, and verifies the host and local directory before building the operation. The same relative path can name a different file on each side.

With a remote destination such as workshop-ssh:training/, the existence and permissions of the target directory affect the operation. Use a specific new destination name when one file is intended. Reusing a filename can overwrite it if the target allows that. A transfer may also fail partway and leave an incomplete result, depending on its mode and the error. For a real deployment, transfer a candidate to a separately managed staging location, verify its identity, then apply the documented promotion mechanism. The lab uses only a unique new training folder, so no service content is in its transfer scope.

Current OpenSSH scp defaults to SFTP, a file-transfer protocol carried over SSH. Authentication can succeed while transfer fails because the server's file-transfer subsystem is unavailable or the permitted view of the filesystem differs from the interactive shell. An older scp can use the legacy protocol, and compatibility options can affect pathname handling. Prefer the server's supported transport and straightforward known paths. If a service uses a confined SFTP-only account, apply its own approved access and use the visible transfer directory. A successful shell login is not part of every file-transfer account's design.

For a directory of workshop artifacts, scp's -r option walks source directories recursively. Review the entire source list, hidden entries, and any symbolic links before using a recursive transfer. OpenSSH scp documents that it follows symbolic links in the tree during recursive copying. A link inside a tree can therefore bring more content into the transfer than the visible directory list alone suggests. An archive created from a reviewed file selection can make the source and expected member paths easier to check. In this exercise only one known file is transferred, so you can verify it directly.

rsync is another tool for repeated synchronization. It can compare two file collections and transfer updated data under its configured options, often using SSH for a remote connection. Typically both ends need compatible rsync support for this style. It has meaningful path rules. With source/ as an ordinary rsync source, the trailing slash means transfer that directory's contents into the specified target. With source and an existing target directory, the source directory name generally appears below that target. Read the planned paths and destination data before using any mode that could remove files. This chapter uses only additive scratch copies and illustrates preview without a deletion workflow.

If rsync is installed locally, a local dry run is a useful way to inspect the trailing slash distinction without modifying the remote training host. The next block compares the declared file plan for two forms. The scratch subdirectories start empty and the one source file has synthetic content. A dry run previews what rsync would consider for this destination. It is still a snapshot of that moment, so another process or different options could change a subsequent live result.

if command -v rsync >/dev/null 2>&1; then
  mkdir "$ssh_lab/sync-source" "$ssh_lab/sync-target"
  printf 'workshop report\n' > "$ssh_lab/sync-source/preview.txt"
  printf 'With a trailing slash:\n'
  rsync -rni "$ssh_lab/sync-source/" "$ssh_lab/sync-target/"
  printf 'Without a trailing slash:\n'
  rsync -rni "$ssh_lab/sync-source" "$ssh_lab/sync-target/"
  if [ ! -e "$ssh_lab/sync-target/preview.txt" ] && [ ! -e "$ssh_lab/sync-target/sync-source" ]; then
    printf 'Dry runs left the target unchanged\n'
  fi
else
  printf 'Optional rsync exercise skipped\n'
fi

The -r option descends into the source directory, -n requests the dry run, and -i requests an itemized report. Formatting differs by version. In the first plan look for a file named preview.txt at the target root. In the second plan look for sync-source/preview.txt under an included directory name. The actual target stays empty. For a remote synchronization workflow, also confirm which setting supplies the same verified SSH session and whether the other side supports the necessary version and operation.

Rsync's ordinary quick comparison usually considers file length and modification time when deciding whether contents need transfer. It can transfer data efficiently for files it has selected, and those are separate decisions. Two files can have the same length and timestamps while their bytes differ. If exact equality matters for a particular artifact, check its content independently or use the tool's documented checksum comparison mode after considering its extra read cost. The dry run here illustrates path placement and a read-only planned action, while the completed scp test compares bytes.

Read failures in the order the connection happens

A message saying the host could not be resolved directs you to the provided name, the active configuration, and its expected lookup context. For a prepared client, inspect the alias with ssh -G to confirm hostname and port. If you received a name whose address changed, confirm the intended destination through the administrator before relying on a stale address. A connection timeout means the TCP connection did not complete within the test conditions. Confirm the route, service address, and approved network boundary rather than repeatedly changing the client identity.

A refused connection can result when no service listens at the reached address and port, or a control sends a rejection. Use the server owner's evidence about its listener and the intended network route. An EC2 access path can require particular security group permissions, subnet and routing arrangements, and a good instance status. Check the approved source and target rather than enabling network access on every interface or port. A host verification warning occurs after the client received an identity and is evaluating trust; alternate routing or a replacement instance can be relevant. A user public-key rejection is later in the path and calls for a check of the account and approved authorizations.

SSH's -v option emits diagnostic details that can identify stages. It can reveal internal hostnames, addresses, account identifiers, file paths, and key fingerprints. Review what you share, and keep private key material, passwords and session tokens out of the diagnostic. If you use a cloud-provided connection method, consult the platform's troubleshooting view for that path. The steps for a direct connection are not automatically the steps for a managed session. Use the known training profile and isolate a single change at a time.

After authentication, a transfer can fail while a simple command succeeds. The remote directory can be unwritable, full, or absent. A file transfer service may show a different visible root than the shell for an intentionally restricted account. A current client can report a missing or unsupported SFTP subsystem. Inspect the operation the server permits and the exact path read by the transfer service. A successful connection alone does not prove the artifact arrived, and a bytes match does not prove a future service can use it. Match every observable check to the goal it can establish.

Check a remote program's result separately from its text

Imagine the workbook handover is part of a long script. The next local step should run only after a remote validation command succeeds. A text line such as “verified” can be useful to a person, but it is also just output the remote program chose to print. Read the command status before deciding whether the next step can run. SSH ordinarily returns the remote command's status when it runs successfully enough to receive that status, and a distinct connection error can return 255. A remote command can itself use any normal status, including 255, so keep the diagnostic rather than classifying every occurrence from the number alone.

On the verified training account you can test an expected low-risk failure without touching any remote files. The command prints one line, writes a deliberately chosen status, and exits. The login and encrypted session need to work for that program to run. The local condition receives the remote result and prints it in a separate line. Do not run the exercise with the documentation-only hostname left in your profile.

if ssh -n -F "$ssh_lab/client.conf" workshop-ssh 'printf "Remote training command ran\n"; exit 7'; then
  printf 'Unexpected status for this fixture\n'
else
  printf 'Status received by local shell: %s\n' "$?"
fi
Remote training command ran
Status received by local shell: 7

There is no contradiction between the message and the failure status. The sentence confirms that the command reached the remote execution stage, and the number communicates its deliberately unsuccessful result. A transport failure would have its own diagnostic and might produce no remote line. A script can handle the fixture's seven as expected in this one test. It should not treat every failure returned by every command as a positive result. For actual file transfer, read each stage's exit separately and require a subsequent content comparison.

An SSH command can relay remote stdout and stderr back to your client. A shell redirect written outside the quoted remote command applies to the local ssh process. For example, running ssh workshop-ssh 'pwd' > returned-path.txt saves the remote command's displayed path in a file on the client, assuming the alias is already configured. A redirection inside the quoted remote command would be interpreted by the remote launcher and refer to remote storage. Treat the local and remote account and directory as explicit boundaries when logging a result. Passing data as a known command argument is different from asking the other shell to interpret a generated program.

If a team reports that a validation was automated, ask which command was reviewed and which evidence prevented release on a failure. A robust routine preserves the local artifact, confirms the remote directory and file identity, and records a clear success message only after all dependent checks pass. The fixed worksheet string makes this practicable for a beginner. With a larger release the same order translates into checking a manifest or trusted digest, then applying an approved promotion action tied to the result. A process that printed a normal-looking progress line can still finish with a nonzero status.

Confirm the relationship of a local key pair with no server involved

An optional offline experiment shows the difference between a private identity and its public part. Generate a one-use practice key in this lesson's scratch directory. The practice key is deliberately not registered on any server, and it is deleted at cleanup. The short generation command uses an empty passphrase only for this disposable fixture. For real access keys use the protection required by the approved identity process. No actual working login keys need to be created, read, or edited in this exercise.

ssh-keygen -q -t ed25519 -N '' -f "$ssh_lab/practice-key"
ssh-keygen -y -f "$ssh_lab/practice-key" > "$ssh_lab/derived.pub"
ssh-keygen -lf "$ssh_lab/practice-key.pub" | awk '{ print "public file fingerprint:", $2 }'
ssh-keygen -lf "$ssh_lab/derived.pub" | awk '{ print "derived fingerprint:", $2 }'
if cmp -s "$ssh_lab/practice-key.pub" "$ssh_lab/derived.pub"; then
  printf 'The complete public lines match\n'
else
  printf 'Check both fingerprints. Public lines can differ by a comment.\n'
fi

The two expected fingerprint fields are identical and start with a label such as SHA256 on common OpenSSH versions. Their exact values are generated for this fixture. The public file format can include a comment that has no part in its key fingerprint, so a complete line comparison can be either more restrictive or redundant for an identity check. To compare just the key, check the algorithm and public key data fields or use the fingerprint. The private bytes never appear in the display. Deriving the public key from a known identity file can help an authorized operator determine which public authorization should correspond to it.

This experiment concerns the user's authentication key. It does not tell you the server's host key fingerprint. That evidence comes from the lab server's owner or the approved provider method for the particular instance. A team can keep a local user key and several trusted server records without confusing the files. When a client says the server identity changed, replacing the local user key does not address that warning. When the server says the user key is not accepted, deleting the server trust record does not make the authorization correct.

If ssh-keygen reports that the practice path already exists, start a fresh scratch directory instead of overwriting a file hidden under the chosen name. The self-contained lesson data begins in a fresh directory and uses simple names so you can inspect every stage. The public fingerprint is safe to compare for this practice key because it is the intended test signal. A real diagnostic should expose only information the authorized recipient needs, and a private identity file should never be attached as evidence that a transfer worked.

Verify which shell expands a value and which path you changed

Try a harmless command that displays the remote home directory after the appropriate host and account are confirmed. The following single-quoted command text reaches the server with the dollar sign still present. The remote shell then expands the variable in its own process. With an outer double-quoted command that directly contained $HOME, the client-side shell could expand it before sending the command. This is a common cause of a remote command trying to use a path meaningful only to the laptop.

ssh -n -F "$ssh_lab/client.conf" workshop-ssh 'printf "remote home: %s\n" "$HOME"'

The expected path belongs to the authorized remote account. It may coincide with its initial working directory on a standard setup, but those are separate observations. If a server starts commands in a non-home directory or gives the transfer subsystem a different view, resolve the authorized target path before writing. Do not guess which prefix is valid by trying several paths. Clear evidence of the intended directory avoids both permission failures and successful writes to the wrong site.

For a team review of a deployment, separate the file transfer from activation. A reviewed original copy can be saved under an approved backup name before making any live change. The candidate can go into the appropriate staging area and be compared with its expected contents. The change owner then applies it using the site's documented release procedure, validating any affected service-specific configuration. A one-file upload exercise does not need these live steps, but it teaches why ownership and scope begin before a successful transfer. If other services share the machine, even a good command needs the site-specific destination and authorized account.

Suppose a transfer appears to succeed but a coworker reports that the page is unchanged. First check what was actually sent and to which path. A matching copy under a training account's home does not become part of a document root by itself. A public hostname can serve through a proxy or cache, so verifying the exact origin and intended response can be another step in a real release. Do not assume scp reloaded a server, changed a cache, or moved a staged file into a live directory. The transport tool delivered data to the one destination it was given.

Batch mode can be useful for later scripted access because it does not stop to ask for inputs that require unattended prompts. It should be used only after the intended host identity is already verified and the approved authentication works without interactive intervention. If an unattended invocation fails, investigate the known profile rather than switching off trust checks or embedding a passphrase in the command. For this lesson an interactive verification is normal when the training endpoint has never been used from the scratch profile before.

Complete a reversible transfer exercise

For the first task, compare the effective client profile with the intended host, user, port, and key path. Run the offline preview first and demonstrate that it requests no connection. Change just the offline example's port from 2222 to 2201 and repeat the preview. The result should show the new port while the username and host stay the same. Restore the appropriate values before any real connection. Identifying the exact option that changed is stronger evidence than assuming a client read the right file.

For the second task, make a handover table with two columns for local and remote. Place the private key, the original worksheet, and the returned copy in the local column. Put the authorized account and operational worksheet path in the remote column. The server host key verification belongs to the handshake between them. After the live copy, compare the returned bytes and record the remote scratch directory. If the laptop's original file still exists and the returned independent copy matches, you can correctly say that the round trip preserved this artifact. Document any unexpected warning and its resolved cause.

For the third task, explain a training failure without trying other systems. If a connection times out, state what network evidence is missing. If the server fingerprint differs from the approved value, state how you would confirm the identity with the lab owner. If the user key is rejected, state why your next check concerns the account and advertised identity rather than the web application port. Each diagnosis should name the last observed stage and a lawful next observation. Record the intended destination without sharing private key material.

Cleanup begins remotely if you created a remote directory in the exercise. Verify that the scratch name in your shell is the name you created, and that the training profile still points to the same authorized account. The command removes just the copied worksheet and then attempts to remove an empty directory. An unexpected file leaves the directory present, which is evidence to inspect separately. If the cleanup cannot connect, keep the information needed to identify the directory for later authorized removal before discarding your scratch profile.

if [ -n "${remote_dir:-}" ]; then
  ssh -n -F "$ssh_lab/client.conf" workshop-ssh \
    "rm -f -- '$remote_dir/worksheet.txt' && rmdir -- '$remote_dir'"
fi

This step assumes remote_dir still holds the checked, generated name from the successful creation step. Do not assign any other path to it. If it is unset because you followed the offline exercise, the command makes no SSH connection. Finally remove known local fixture names and their empty directories after saving any approved nonsecret notes. You never need to remove your working identity file or edit your existing SSH settings for the lesson.

if [ -n "${ssh_lab:-}" ] && [ -d "$ssh_lab" ]; then
  printf 'Cleaning lesson fixtures in %s\n' "$ssh_lab"
  rm -f -- "$ssh_lab/client.conf" "$ssh_lab/known_hosts" "$ssh_lab/worksheet.txt" \
    "$ssh_lab/returned.txt" "$ssh_lab/practice-key" "$ssh_lab/practice-key.pub" \
    "$ssh_lab/derived.pub" "$ssh_lab/sync-source/preview.txt"
  if [ -d "$ssh_lab/sync-source" ]; then rmdir -- "$ssh_lab/sync-source"; fi
  if [ -d "$ssh_lab/sync-target" ]; then rmdir -- "$ssh_lab/sync-target"; fi
  rmdir -- "$ssh_lab"
fi
unset ssh_lab ssh_suffix remote_dir

Explain the identity and transfer checks

Interview question. Which key identifies the server and which identifies the user?

The server's host key identifies the destination to the client and should be checked independently when unfamiliar or changed. The user authenticates to an approved account using a private identity whose public part the server authorizes. The private file stays on the user side. The two checks occur in different directions and solve different problems.

Interview question. How do you prove a copied file arrived as expected?

Identify the authorized host, account, exact destination path and expected artifact. Check the transfer command status, then compare known contents or the expected digest with the received file. In the lab an independently named returned copy matches the unchanged local original. Confirm application behavior separately if the work includes a deployment.

Quiz. An scp operand named workshop-ssh has no colon. How is it interpreted?

As a local pathname in this form. The remote operand uses a host and colon, such as workshop-ssh:training/worksheet.txt. Confirm which machine starts the scp command, because that determines what local means.

Quiz. A host key unexpectedly changes. What do you check before editing known hosts?

Confirm the intended name, port, and server with a trustworthy administrator or console, then compare the new fingerprint and algorithm independently. Update only the affected entry after confirming the legitimate change. Keep verification enabled so the next connection can check that trust decision again.

Quiz. Login works but scp cannot write the worksheet. Which boundary should you examine next?

Inspect the file-transfer access and target path for the same account. The destination may be unwritable, full, or outside the configured SFTP view. The login evidence establishes that the connection and account authentication worked. It does not prove any particular write is permitted.

Revision cards

Verify the destination independently

Match the expected host name, port, and server fingerprint before entering account authentication.

Read local and remote paths literally

The local machine is where the client runs. Use host-colon-path for the approved remote endpoint and verify the expected contents after transfer.

Connect, authenticate, transfer, verify

Each stage establishes a different fact. Choose the next check based on the last stage you can prove.

Primary references