From e3924c1fdbde747e6e32420d2e6857b74fd6a85a Mon Sep 17 00:00:00 2001 From: Andrei Shevchuk Date: Mon, 22 Feb 2021 23:47:21 +0000 Subject: [PATCH] Created Export configuration password to env variable and only remember it for some time (markdown) --- ...able-and-only-remember-it-for-some-time.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Export-configuration-password-to-env-variable-and-only-remember-it-for-some-time.md diff --git a/Export-configuration-password-to-env-variable-and-only-remember-it-for-some-time.md b/Export-configuration-password-to-env-variable-and-only-remember-it-for-some-time.md new file mode 100644 index 0000000..ced1ab7 --- /dev/null +++ b/Export-configuration-password-to-env-variable-and-only-remember-it-for-some-time.md @@ -0,0 +1,28 @@ +As [configuration encryption docs](https://rclone.org/docs/#configuration-encryption) mention: +> If it is safe in your environment, you can set the `RCLONE_CONFIG_PASS` environment variable to contain your password, in which case it will be used for decrypting the configuration. + +It also provides a short script to do so, which can be improved to only remember your password for some time (similar to `sudo`). For Unix like systems you can save this to a file somewhere in your `$PATH`, e.g. `~/.local/bin/rclone-unlock` + +```sh +#!/bin/echo Source this file don't run it + +echo "Password:" + +read -s RCLONE_CONFIG_PASS +export RCLONE_CONFIG_PASS + +if [ -n $RCLONE_PASS_TIMEOUT ]; then + pid=$$ + trap 'unset RCLONE_CONFIG_PASS' SIGALRM + ( ( sleep $RCLONE_PASS_TIMEOUT ; kill -ALRM $pid ) & ) + + echo -n "Password will be remembered in this session for $RCLONE_PASS_TIMEOUT" + [[ $RCLONE_PASS_TIMEOUT =~ [smhd] ]] && echo || echo " seconds" +fi +``` + +Then source this file when you want to use it: `. rclone-unlock`. It will then ask you for the password and set it in the environment variable. + +If you set password timeout to some amount of time (in format [`sleep`](https://manpages.debian.org/testing/coreutils/sleep.1.en.html) accepts) with `RCLONE_PASS_TIMEOUT` environment variable, `RCLONE_CONFIG_PASS` will be unset after that time. + +You can also clear `RCLONE_CONFIG_PASS` sourcing `rclone-unlock` as usual and then just hitting Enter (thus setting empty password). \ No newline at end of file