Good evening, everybody!
I’ve got a problem with connecting to the remote server using ssh keys and can’t resolve it. I’ve searched in this forum and google, but didn’t find topics with information i need.
So, what i’ve done:
generated ssh keypair id_rsa, id_rsa.pub in folder ~/.ssh (i’m on windows)
cloned trellis from repository
added all nessesary information in configuration files (paths to the keys are “{{ lookup(‘file’, ‘~/.ssh/id_rsa.pub’) }}” in group_vars/all/users)
ran ‘vagrant up’ from trellis folder
created new digital ocean droplet, adding public key from ~/.ssh/id_rsa.pub (that was generated in step 1)
tried to setup the remote server, but ansible command ‘ansible-playbook server.yml -e env=production’ failed with error ‘Failed to connect to the host via ssh: Permission denied (publickey).’
What did cause it? How can i solve that?
p.s. i can connect to vagrant with ‘vagrant ssh’ command, and also i can connect to the remote DO server with ‘ssh -i ~/.ssh/id_rsa root@111.111.1.111’ , but connection fails each time i try to run server.yml
What environment are you using in Windows? Are you in WSL? Generally Windows doesn’t have a ~ directory otherwise.
Trellis (especially if you’re using the Windows technique that uses the VM for running ansible) uses SSH Agent Forwarding, which essentially passes on your local SSH credentials to a remote server to allow that remote server to authenticate as you. 80% of the internet tutorials on setting up SSH assume a *nix environment, so information on how to do this on Windows can be hard to find. Fortunately, pageant supports Agent Forwarding, so adding your key to pageant might solve your problem.
Thank you for reply,
what do you mean ‘enviroment’ ? i did’t install anything special. But if i type ‘~’ in termial, and then ‘ls’ - it outputs all folders and files of a user directory, so i suppose my windows version has ‘~’ directory.
Putty programm (which link you mentioned in your reply) connect to the remote server, but not to the local. I specify ip 192.168.50.5 (vagrant ip from docs) with username vagrant, and connection fails with error ‘No supported authentitification methods available’ so i can’t even run ansible server.yml command with putty, because can’t log in
I didn’t say anything about putty. pageant is the piece of software that holds and supplies SSH keys. You need to make your SSH keys available to other software on your system, pageant will do that on Windows.
cmd does not have ~. When I asked about your environment, I asked how you were accessing the command line. On Windows, people are generally using cmd, which does not have ~, so you’re using something else. What is it? You might be using Git Bash, or PowerShell, or WSL, or Cygwin—all of which could have implications for what you’re doing. There are specific instructions for using Trellis on Windows: https://roots.io/trellis/docs/windows/ I would recommend reading them over if you haven’t already.
unfortunately, pageant didn’t help. i configured putty (set authentification method to pageant), and added the key to pageant. when try to connect, putty return ‘No supported authentification methods available’.
i noticed, that the private vagrant key from the folder trellis\.vagrant\machines\default\virtualbox\private_key doesn’t match my private key from ~/.ssh folder, so i assume, vagrant could replace my keys with its own on first ‘vagrant up’.
But when i try to fix it, accordingly to some tutorials from google, adding these lines to trellis/Vagrantfile: config.ssh.insert_key = false config.ssh.private_key_path = ["~/.ssh/id_rsa", “~/.vagrant.d/insecure_private_key”] config.vm.provision “file”, source: “~/.ssh/id_rsa.pub”, destination: "~/.ssh/authorized_keys"
‘vagrant up’ command throws the error: ‘default: Warning: Authentication failure. Retrying…’
maybe you could tell me what is the right way to force trellis vagrant use only my key from ~/.ssh?