ShellSage
ShellSage mobile SFTP file transfer workflow
SSH BASICS

How to Upload Files to a Linux Server Using SSH

Learn how to securely upload files to a Linux server over SSH with step-by-step instructions and practical examples.


To upload a file to a Linux server over SSH, you can use the scp command, which securely transfers files between hosts using the SSH protocol. The basic syntax is scp localfile user@host:/remotepath.

What is SCP and How Does it Work?

The scp (Secure Copy Protocol) command is a secure and efficient way to transfer files between computers over an SSH connection. It encrypts the file data and any passwords exchanged, ensuring that your data remains confidential during transit. This makes scp a preferred method for transferring files, especially over unsecured networks.

The basic syntax of scp is as follows:

scp [options] localfile user@remotehost:/remotepath

Here, localfile is the file you want to transfer, user is your username on the remote server, remotehost is the server's address, and /remotepath is the destination directory on the server.

The scp command encrypts file data and passwords, maintaining confidentiality.

Options like -P for specifying a port or -r for recursive copying can be used to modify the behavior of scp. For instance, scp -P 2222 file.txt user@host:/path would use port 2222 instead of the default port 22.

How to Use SCP to Upload a File

To upload a file using scp, open your terminal and enter the following command:

scp localfile.txt user@remotehost:/path/to/destination

This command will prompt you for your password on the remote server. Once authenticated, the file will be transferred to the specified directory on the server. If you need to upload a directory and all its contents, use the -r option:

scp -r localdirectory user@remotehost:/path/to/destination

Remember, the path on the remote server must be accessible to the user you are logging in as. If permissions are incorrect, you might encounter errors.

Ensure the remote path is accessible to avoid permission errors.

I once spent hours debugging a failed transfer, only to realize I was trying to write to a directory I didn’t have permission for. Always double-check your paths and permissions!

Using SSH Keys for Passwordless Authentication

Entering your password each time you transfer files can become tedious. SSH keys provide a way to authenticate without using a password. First, you'll need to generate an SSH key pair on your local machine using:

ssh-keygen -t rsa

This generates two files: id_rsa (the private key) and id_rsa.pub (the public key). You need to copy the public key to the ~/.ssh/authorized_keys file on the remote server:

ssh-copy-id user@remotehost

After setting up SSH keys, you can use scp without a password prompt:

scp localfile.txt user@remotehost:/path/to/destination

This method not only saves time but also enhances security by eliminating password transmissions.

When Should You Use SCP Over Other Methods?

While there are several methods to transfer files, such as FTP, SFTP, and rsync, scp is particularly useful for its simplicity and security. It's ideal for quick transfers where you need to ensure the confidentiality of the data.

Comparatively, tools like Termius, JuiceSSH, and Blink Shell provide mobile SSH capabilities but often lack features like AI assistants or blast-radius previews. ShellSage, on the other hand, offers Sage AI for explaining outputs and fixing commands, making it easier to manage transfers from a phone.

For larger or more complex file transfers, consider using rsync for its efficiency in handling large datasets and incremental backups.

Common Issues and Troubleshooting

One common issue with scp is permission errors. Always ensure that the destination directory is writable by the user you're logged in as. Another problem could be network issues, preventing connectivity to the remote server. Use ping to check connectivity:

ping remotehost

If you encounter issues with the scp command itself, use the verbose option -v to get more detailed output:

scp -v localfile.txt user@remotehost:/path/to/destination

This can help diagnose problems by providing more information about what scp is doing under the hood.

⚡ Key takeaways

Marcin Migdal
Your Questions, Answered

Frequently Asked Questions

To transfer files over SSH, you can use the 'scp' command, which securely copies files between hosts using the SSH protocol. The basic syntax is 'scp localfile user@remotehost:/remotepath'. ShellSage simplifies this process on mobile by allowing you to use voice commands to initiate file transfers.
Yes, you can use an SSH terminal on a phone. There are several apps available that allow you to connect to a remote server using SSH from your mobile device. ShellSage provides an AI-first SSH experience on mobile, enabling features like voice input and AI assistance for managing SSH sessions.
The 'scp' command is used to securely transfer files between a local and a remote host over SSH. It ensures that data and passwords are encrypted during the transfer. ShellSage supports file transfers via scp, allowing you to manage uploads and downloads directly from your phone.
ShellSage offers a free version with basic features, allowing users to experience its core functionalities. There may be premium options available for advanced features and capabilities.
On the device, your key sits in encrypted secure storage (iOS Keychain / Android EncryptedSharedPreferences) behind an optional Face ID or fingerprint gate you can require per host. When you save a host, that key or password is also uploaded to ShellSage's servers and stored encrypted at rest with AES-256, which is what lets your saved hosts appear on any device you sign in on. To be precise: this is encryption at rest, not end-to-end encryption , ShellSage holds the decryption key and returns the secret to the app at connect time. Deleting a host deletes its stored secret.
Yes, ShellSage includes an AI assistant named 'Sage' that can help execute complex commands and provide suggestions, making it easier to manage SSH sessions on your mobile device.
ShellSage requires an internet connection to perform SSH and SFTP operations, as these actions involve connecting to remote servers. However, some local features like managing saved sessions or viewing logs may be accessible offline.
Download ShellSage free
ShellSage is an AI-first SSH terminal with Sage built in: it explains output, fixes broken commands, and previews the blast radius before anything runs. Start on the free Hobby plan with no credit card, and get a 7-day full-Pro trial when you want everything.
← More tutorials