Share Files with pbput Without Losing Track of Them
pbput pushes a file, a directory, or a stream of standard input straight to a paste service, and pbget is what pulls it back down on the other end. Reach for pbputs instead when the content has to be encrypted before it leaves your machine. Allow about fifteen minutes. You need a shell, the pastebinit package, network access to the configured paste service, and enough free space for temporary compression and archive files.
The route
Jump straight to the step you need, or tick off Done means at the end.
The examples below describe the installed Debian package version pastebinit 1.6.2-1. This copy sends to paste.ubuntu.com, as the installed script itself shows, which differs from the older manpage wording naming pastebin.com. Trust whatever URL your own command actually prints as the record of where to retrieve the paste.
1. Check the installed tools
Start with read-only checks, ordinary commands that need no sudo:
$ command -v pbput pbputs pbget
/usr/bin/pbput
/usr/bin/pbputs
/usr/bin/pbget
$ dpkg-query -W -f='${Package} ${Version}\n' pastebinit
pastebinit 1.6.2-1
pbput and pbputs are the same shell program, chosen by the name used to invoke it. Both always compress with lzma and encode with base64 before handing off to pastebinit, and pbget reverses the whole process. An upload is a write to an external service, so keep real secrets and private customer data out of it while you are just learning the workflow.
Checkpoint
Stop here if any of the three commands is missing, or if the installed version and service differ from these examples. Do not install packages just to force a copied example to fit.
2. Upload text from standard input
Pipe a short, non-sensitive value to pbput when you want the receiver to get the original stream rather than an extracted file tree:
$ printf '%s\n' 'pbput smoke test' | pbput
https://paste.ubuntu.com/p/EXAMPLE/
The URL is different every time. Save it immediately, it is the handle pbget needs later. Checking the exit status is the first local sanity check:
$ printf '%s\n' 'pbput smoke test' | pbput > /tmp/pbput-url
$ status=$?
$ printf 'upload status: %s\n' "$status"
upload status: 0
$ sed -n '1p' /tmp/pbput-url
https://paste.ubuntu.com/p/EXAMPLE/
A plausible-looking URL is not proof the content is correct. The service can reject a request, return an unexpected page, or expire the paste later. Remove the temporary URL file once you are done checking it, but remember that deleting your local copy does nothing to the remote paste.
3. Upload one file or a directory
Pass a readable path and pbput tars it first, which preserves the file or directory structure and attributes ahead of compression:
$ mkdir -p /tmp/pbput-example
$ printf '%s\n' 'example data' > /tmp/pbput-example/notes.txt
$ pbput /tmp/pbput-example/notes.txt
https://paste.ubuntu.com/p/EXAMPLE/
No elevated privileges needed when the source and destination both belong to you. The command reads the path and creates temporary files under /tmp, it does not touch the source. A directory works the same way:
$ pbput /tmp/pbput-example
https://paste.ubuntu.com/p/EXAMPLE/
Quote the path when it contains spaces or shell metacharacters, for example pbput -- "$HOME/my reports". The installed script documents no real option parser, so do not treat -- as a general-purpose flag: prefer a path that does not start with something that looks like an option, such as ./-notes.
Tip
If the first argument is not readable, the installed script quietly falls back to reading standard input. A mistyped filename can therefore look like a hang while it waits for you to type something. Cancel with Ctrl-C, check the path without touching anything, and try again:
$ test -r /tmp/pbput-example/notes.txt && echo readable
readable
$ ls -ld /tmp/pbput-example/notes.txt
4. Retrieve and verify the result
Hand the saved URL to pbget. With no destination directory, an archived upload gets extracted into a fresh temporary directory:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/'
tmp/pbput-example/notes.txt
INFO: Output is in [/tmp/pbget.ABC123]
$ find /tmp/pbget.ABC123 -type f -print
/tmp/pbget.ABC123/tmp/pbput-example/notes.txt
The exact paste URL, temporary directory name and extracted listing will all vary for you. For a plain standard-input upload, pbget writes the decoded content to standard output instead:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/'
pbput smoke test
Want a controlled extraction location? Create an empty directory and pass it as the second argument:
$ install -d -m 700 /tmp/pbput-restore
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' /tmp/pbput-restore
tmp/pbput-example/notes.txt
INFO: Output is in [/tmp/pbput-restore]
$ find /tmp/pbput-restore -type f -print
Check the restored files before moving them into a real project. A download is remote input even when the URL came from a colleague you trust. Do not extract into a directory holding valuable files unless you have inspected the archive and are ready for existing paths to be touched.
5. Encrypt with pbputs when confidentiality matters
pbput compresses and encodes, it does not encrypt. Anyone who gets hold of the paste and decodes it can read the content. Reach for pbputs instead when that matters:
$ pbputs /tmp/pbput-example/notes.txt
Enter passphrase:
https://paste.ubuntu.com/p/EXAMPLE/
With one readable path, the installed command tars it and then applies symmetric GPG encryption, prompting for a passphrase rather than putting it on the command line. Retrieve with the matching passphrase:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' /tmp/pbput-restore
Enter passphrase:
For standard input, put the GPG user as the first argument to pbputs for public-key encryption, or leave it off for a passphrase prompt instead. A target user has to already exist in your GPG keyring:
$ printf '%s\n' 'encrypted example' | pbputs
Enter passphrase:
https://paste.ubuntu.com/p/EXAMPLE/
Never put a passphrase, private key material or sensitive data in shell history. Encryption does not hide the fact that a paste exists, and losing the passphrase or the required private key makes recovery impossible. The remote paste stays put until the service removes it: deleting your local copy is not a recall button.
6. Recover from failures and clean up
If pbget prints nothing useful, check the URL and your network access first. Then retry with a known-good paste and look at the command's status:
$ pbget 'https://paste.ubuntu.com/p/EXAMPLE/' > /tmp/pbget-output
$ printf 'download status: %s\n' "$?"
download status: 0
$ file /tmp/pbget-output
A zero status does not validate the contents. Compare a checksum if you have an independent expected value, or inspect the extracted files and their permissions directly. Do not run a restored file just because pbget extracted it successfully.
Once you have verified everything, the temporary directories and test files from these examples can go:
$ rm -r -- /tmp/pbput-example /tmp/pbput-restore
$ rm -f -- /tmp/pbput-url /tmp/pbget-output
Those removals are permanent for the local copies. Check the paths before running them, and resist the urge to swap the explicit paths for a broad directory or a wildcard. Cleaning up locally does nothing to an already-uploaded paste.
Done means
- Tools verified. You checked the installed
pastebinitversion and where the commands live. - Source understood. You know whether your input came from standard input or from a tar archive.
- URL saved. You saved and tested the URL returned by the upload.
- Encryption applied where it mattered. You used
pbputsfor content that needed it, keeping the passphrase or key off the command line. - Recovery checked. You restored into a controlled directory and inspected remote content before trusting it.
- Deletion understood. You know that removing local files does not remove the remote paste.