I can mount my ubuntu homeserver trough sftp using the rclone mount command. What also works is:
mount raspi: /home/ejan/Openbaar/Homeserver -t rclone -o config=/home/ejan/.config/rclone/rclone.conf,vfs_cache_mode=writes,sftp_key_file=/etc/ssh/id_rclone
Unfortunately I can't mount using a systemd script on startup, however when I start the systemd mount service after booting up my computer mounting my Ubuntu server's homefolder works.
Run the command 'rclone version' and share the full output of the command.
rclone v1.63.0
os/version: arch "rolling" (64 bit)
os/kernel: 6.1.38-2-lts (x86_64)
os/type: linux
os/arch: amd64
go/version: go1.20.5
go/linking: dynamic
go/tags: none
Which cloud storage system are you using? (eg Google Drive)
Ubuntu homeserver on Raspberrypi trough SFTP.
The command you were trying to run (eg rclone copy /tmp remote:tmp)
cat /tmp/rclone-raspi.log
2023/07/29 00:11:29 Failed to create file system for "raspi:": couldn't connect to ssh-agent: Error connecting to SSH_AUTH_SOCK: dial unix /run/user/1000/keyring/ssh: connect: no such file or directory
Actually, this is what's so confusing to me: If I go without the option key_use_agent I get this feedback after rclone mount raspi: /home/ejan/Openbaar/Homeserver
2023/07/29 16:29:45 Failed to create file system for "raspi:": failed to parse private key file: ssh: not an encrypted key
However this is what the official rclone documentation states on creating a PEM-encoded ssh keyfile for sftp:
Key files should be PEM-encoded private key files. For instance /home/$USER/.ssh/id_rsa . Only unencrypted OpenSSH or PEM encrypted files are supported.
Like this: ssh-keygen -P "" -a 100 -t rsa -b 4096 -m pem -f id_rclone -C "ejan@rclonemount" I did not set a passphrase. Since this created just a private and public key, I followed some instructions on how to convert your public key to a pem encoded key (not sure if this is the right way) with: ssh-keygen -f id_rclone.pub -m 'PEM' -e > id_rclone.pub.pem
If you have a certificate you may use it to sign your public key, creating a separate SSH user certificate that should be used instead of the plain public key extracted from the private key. Then you must provide the path to the user certificate public key file in pubkey_file.
Note: This is not the traditional public key paired with your private key, typically saved as /home/$USER/.ssh/id_rsa.pub. Setting this path in pubkey_file will not work.
Based on your description how you generate it I think in your case just remove pubkey_file
then
rclone mount raspi-test: /home/ejan/Openbaar/Homeserver
should work with:
[raspi-test]
type = sftp
host = 192.168.2.242
user = ???
key_file = /etc/ssh/id_rclone
It will also work in systemd during startup. If you want to use ssh-agent you have to make sure that it is running before.
I suspect that when you do not use agent rclone tries to decrypt key_file using key_file_pass (which I have no idea why you use in your config - remove it too). Your private key is not encrypted so it fails.
Thank you very much, that indeed works fine. I guess the confusing part for me is whether or not to use an encrypted ssh key and because of being restricted to use a PEM encoded public keyfile. So correct me if I'm wrong, you should only use a pub_keyfile if you set a passphrase when you generate a ssh key? You then should create a pem encoded public keyfile?
Ok. I think I understand it now. pub_keyfile has nothing to do with encryption and passphrases...
You use encrypted private key (there is no need to encrypt public one) and --sftp-key-file-pass flag pointing to password file when your goal is to protect your key from unauthorized use. It is up to you how you solve password protection part. Usually this is what ssh-agents do. But with --sftp-key-file-pass you can have your own solution.
Now all your ssh infrastructure can be designed to only trust signed keys. If you have certificate you can use it to sign keys to be trusted (assumption is all machines know and trust this certificate). In such case you can use pub_keyfile pointing to signed public key (not encrypted) to explicitly advertise its trustworthiness. And thx to signing it can be verified by others.
You can use both/one/none from the above. When using all it requires some openssh standard reading as things quickly are becoming a bit complex.
Thanks again for taking a deep dive into this subject. I really appreciate your efforts. It seems like option 1 looks a lot like the way full disk luks encryption works. I'll have to look into this further since I do care about security.