2

I'm working on a small ruby script that will checkout and sync a branch on two different servers. I'm trying to figure out how to pass a password to git when pulling. Right now I have

Net::SSH.start(host, user, password: password) do |ssh|
  # other code....
  result = ssh.exec!("git pull")
  # results in Enter passphrase for key '/root/.ssh/id_rsa'
end

After running the git command it get a prompt for the key passphrase.

Is it possible to pass that in with a git command? Or is there another way to do that within ruby?

sneakyfishies
  • 165
  • 10

1 Answers1

1

The net-ssh documetation does mention the method Net::SSH.start() accepts a passphrase argument:

passphrase
the passphrase to use when loading a private key (default is nil, for no passphrase)

So if you can get the passphrase (from a file or environment variable) in your program, you can add that argument to the Net::SSH.start() method.

Once you are connected, however, it is best to:

  • use a passphrase-less key for Git SSH URL
  • or use an HTTPS URL instead, for git pull commands, since you can register once and for all the password (not passphrase) associated with that HTTPS URL in a credential storage.

Using a passphrase means adding to your SSH session:

That seems quite cumbersome.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • How can I pass in a general password when I've SSHed into the machine? I've been using that to get into it but, I have not been able to pass the password to git afterwards. – sneakyfishies Feb 21 '22 at 08:28
  • 1
    @sneakyfishies I have edited the answer to answer your comment. – VonC Feb 21 '22 at 08:37