ruby-on-railsgitrugged

Error occuring when trying to clone github repo with SSH credentials using rugged


When trying to clone a remote repo with Rugged, I keep getting the error Failed to authenticate SSH session: Unable to open public key file

I add my ssh credentials fine, but when I come to doing the clone the above error occurs.

cred = Rugged::Credentials::SshKey.new({username: 'gabriel403', publickey: publickey, privatekey: privatekey})
Rails.logger.debug cred

Where publickey and privatekey are string holding the keys.

repo = Rugged::Repository.clone_at('git@github.com:gabriel403/dotfiles.git', '/tmp/dotfiles', {credentials: cred})
Rails.logger.debug repo

Solution

  • :publickey and :privatekey need to be expanded paths to the public and private key file locations on the disk. If your application works with the key data directly, you could try writing the data to tempfiles and passing in the paths to those files.

    Just make sure to understand possible security risks when doing that.