CloudsArk
Commands Linux

scp with Custom Port and Key in Linux

Learn advanced and troubleshooting-focused scp usage for practical Linux administration.

scp with Custom Port and Key in Linux

Introduction

Advanced scp usage helps when the basic form is not enough. This article focuses on realistic command patterns that are useful during administration and troubleshooting.

When You Need Advanced Usage

Use scp for simple one-time file transfers over SSH. For repeated syncs or large directory trees, rsync is often a better tool. Advanced usage is most useful when you need to narrow scope, work on multiple targets, or diagnose why the first command did not answer the question.

Practical Examples

Inspect first:

ssh admin@server ls -l /tmp/file.txt

Run a focused command:

scp -r project admin@server:/srv/

Use a real-world pattern:

scp -P 2222 -i ~/.ssh/id_rsa file.txt admin@server:/tmp/

Troubleshooting

If scp does not give the expected result, verify the target first with ssh admin@server ls -l /tmp/file.txt. Then check permissions, paths, service state, network reachability, package repositories, or process state depending on what the command manages.

Example output:

-rw-r--r-- 1 admin admin 1200 May 30 10:00 /tmp/file.txt

Common Mistakes

  • Using lowercase -p when you meant uppercase -P for port.
  • Forgetting -r when copying a directory.
  • Putting the colon in the wrong place in a remote path.

Safety Notes

Use a preview, backup, dry run, read-only command, or smaller test target before applying broad, recursive, destructive, or remote operations.

Summary

Advanced scp usage should still be controlled. Build the command step by step and verify the result separately.