All posts in "Uncategorized"

Extract a file from a Linux host

I often find myself SSH’d into a Linux host and needing to retrieve a file from that host so that I can use the file on my local machine.

Occasionally, I create a second connection to the Linux host using SFTP to retrieve the file. That requires the file to be visible in my home directory and owned by my user, which often means that I must first copy the file within the SSH connection and `chown` it so that I have rights.

Other times, I may move the file into a directory that’s served by the host’s web server and download it that way.

Neither of these methods are ideal. They either require more work than I’d like, or they risk inadvertently exposing information publicly.

Today, I found my new favorite solution.

Using this single-line curl command on the Linux host, the file can be easily uploaded to transfer.sh, which will then provide a unique URL to download the file using any web browser. By adding openssl encryption inline, the file is encrypted before being sent.

openssl enc -aes-256-cbc -a -salt -md md5 -in INPUT_FILE_HERE -pass pass:PASSWORD_HERE | curl --upload-file - https://transfer.sh/file

After running the upload command, a URL will be output. On the receiving computer, use this command to download the file and decrypt it:

curl URL_TO_FILE_HERE | openssl enc -d -aes-256-cbc -a -md md5 -out OUTPUT_FILE_HERE -pass pass:PASSWORD_HERE

There is another service similar to transfer.sh, called filepipe.io. Here’s the command to send the file to filepipe.io (the same decrypt command, above, will work):

openssl enc -aes-256-cbc -a -salt -md md5 -in FILENAMEHERE -pass pass:PASSWORDHERE | curl --upload-file - https://api.filepipe.io/upload.php
>