How to use deploy ssh key to clone private repos using Chef 12 on AWS OpsWorks - github

I could clone public repos using Chef 12 on AWS OpsWorks as follows:
execute "get code" do
user "root"
cwd node['conf-cookbook']['project_root']
command "git clone #{app['app_source']['url']}"
end
but I don't know how to use deploy ssh key to clone private repos - I have searched a while and see a potential solution as follows:
git node['conf-cookbook']['app_dir'] do
repository "ext::ssh -i #{app['app_source']['ssh_key']} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no #{app['app_source']['url']}"
checkout_branch "master"
action :sync
end
which did not work with the error msg:
---- Begin output of git ls-remote "ext::ssh -i -----BEGIN RSA PRIVATE KEY----
MIIJKQIBAAKCAgEApaViIRinBrusrE....[key detail]7xAOmo3NAmqcPxdrOI+hZJHh5KRvrQPLHY
-----END RSA PRIVATE KEY----- -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no git#github.com:harrywang/app-main.git" "HEAD" ----
STDOUT:
STDERR: Warning: Identity file -----BEGIN not accessible: No such file or directory.
ssh: Could not resolve hostname rsa: Name or service not known
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Any help? Thanks!

the following works according to #coderanger's suggestion:
application node['conf-cookbook']['app_dir'] do
git app['app_source']['url'] do
deploy_key app['app_source']['ssh_key']
end
end

-i takes a path to a key file, not the actual key data itself. Use the application_git cookbook for setting up deploy keys with Chef.

Related

Host key verification failed bitbucket pipeline

Hi i have a problem configuring bitbucket pipeline with ssh login on my remote server.
The output of error is:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Host key verification failed
These are the steps i follow:
generate private and public keys (without password) on my server using this command: ssh-keygen -t rsa -b 4096
add base64 encoded private key under Repository Settings->Pipelines->Deployments->Staging environments
push file "my_known_hosts" on the repository created with: ssh-keyscan -t rsa myserverip > my_known_hosts
I also tried to do another test:
generate keys from Repository Settings
copy public key to authorized_keys file on my remote server
type the ip of my remote server in "Known hosts" click fetch and add
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
This is how i configure pipeline ssh connection
image: atlassian/default-image:latest
pipelines:
default:
- step:
name: Deploy to staging
deployment: staging
script:
- echo "Deploying to staging environment"
- mkdir -p ~/.ssh
- cat ./my_known_hosts >> ~/.ssh/known_hosts
- (umask 077 ; echo $SSH_KEY | base64 --decode > ~/.ssh/id_rsa)
- ssh $USER#$SERVER -p$PORT 'echo "connected to remote host as $USER"'
I'm trying all possible things but still can't connect.
Can anyone help me?
This happen when you try to ssh the first time to the server, you can remove host checking by this option StrictHostKeyChecking=no, below is the complete command for your reference.
ssh -o StrictHostKeyChecking=no $USER#$SERVER -p$PORT 'echo "connected to remote host as $USER"'
PS: disabling host checking is not secure way to do, you can add server key to your ~/.ssh/known_host , run this command ssh-keyscan host1 , replace host1 to the host you want to connect.

SSH issue with GitHub and terminal after push origin master

I am stuck with after statement "couldn't get a file descriptor referring to console". I couldn't continue further than that. I need your help on this issue. I am a new web developer and continue to learning to improve my skills. Thank you for your time to guide me to right direction.
[ENV]:/vagrant/src/splurty $ git push origin master
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[ENV]:/vagrant/src/splurty $ git remote set-url origin https://github.com/livestronger08/brolin.git
[ENV]:/vagrant/src/splurty $ eval "$(ssh-agent -s)"
Agent pid 30162
[ENV]:/vagrant/src/splurty $ ssh-add
Identity added: /home/vagrant/.ssh/id_rsa (/home/vagrant/.ssh/id_rsa)
[ENV]:/vagrant/src/splurty $ $ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
$: command not found
[ENV]:/vagrant/src/splurty $ ssh-keygen -t rsa -b 4096 -C "derek.downie#ttu.edu"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
/home/vagrant/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Passphrases do not match. Try again.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
The key fingerprint is:
72:98:32:bc:e7:b1:05:0e:c6:99:17:3d:a0:00:6a:63 derek.downie#ttu.edu
The key's randomart image is:
+--[ RSA 4096]----+
|... . |
|. . . o |
|.E . . o |
|o .o o + . |
| X * S |
| . B + |
| . + . |
| o + |
| o |
+-----------------+
[ENV]:/vagrant/src/splurty $ eval
[ENV]:/vagrant/src/splurty $ eval "$(ssh-agent -s)"
Agent pid 30176
[ENV]:/vagrant/src/splurty $ open ~/.ssh/config
Couldn't get a file descriptor referring to the console
[ENV]:/vagrant/src/splurty $ touch ~/.ssh/config
From the moment you have set the remote repository URL (with git remote set-url origin https://github.com/livestronger08/brolin.git) to an HTTPS one, every other commands related to SSH won't matter regarding the authentication.
The agent is needed only if you have entered a non-empty passphrase when creating the SSH key.
And the ~/.ssh/config is a file needed only if your SSH key is not the default ~/.ssh/id_rsa name. In your case, you don't need it.

GIT push with SSH

I am having create difficulty finding reliable information on creating SSH keys in order to remove the need for username and password when doing git push and pull for a main repo and separate nested repos.
To make sure I have no existing errors deleted them from
https://github.com/settings/keys
And then followed this guide which in a nutshell advises:
Check for existing, I deleted all from here as well
ls -al ~/.ssh
then (accepting defaults with no passkey)
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
clip < ~/.ssh/id_rsa.pub
and pasting key at https://github.com/settings/keys
The guide seems to end here, however attempt to push the repo gives:
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com':
What steps have been missed here please.
Attempting to push via git bash

Dockerfile: skip passphrase for private key

I'm using private keys for downloading my repository from Github in my Docker file. I have something like this:
RUN mkdir -p /root/.ssh && echo "$MY_PRIVATE_KEY" >/root/.ssh/id_rsa && chmod 0600 /root/.ssh/id_rsa && ssh-keyscan github.com >> /root/.ssh/known_hosts && cat /root/.ssh/known_hosts && ssh -vvv git#github.com && pip install git+ssh://git#github.com/my_project.git#v1.0.0 && rm /root/.ssh/id_rsa
Where MY_PRIVATE_KEY is an argument. I'm not able to re-create this key.
My issue is that during connection process I'm getting the following error:
key_load_private_type: incorrect passphrase supplied to decrypt private key
Is it possible to skip passphrase somehow?
The passphrase is required to decrypt the key. You can't "skip" it. You could remove the passphrase on the key using ssh-keygen -p (see the man page for details).
You may want to investigate the use of a GitHub Deploy Key, which is a per-repository ssh key that grants read-only access to the repository. These are meant to solve exactly the situation you find yourself in: needing to automaticaly deploy software from a GitHub repository that requires authentication.
Your MY_PRIVATE_KEY seems to be passphrase-protected (a key with an empty passphrase is not the same as a non-encrypted key).
The key in .ssh/id_rsa is normally not passphrase-protected, instead it is protected by permissions to allow only owner access (0600).
You can remove the passphrase from your key using OpenSSL like this:
set MY_PRIVATE_KEY = `echo $MY_PRIVATE_KEY | openssl rsa`
The contents of id_rsa should look like:
-----BEGIN RSA PRIVATE KEY-----
. . .
-----END RSA PRIVATE KEY-----
I had the similar issue and it turns out the reason is the ssh key was copied differently due to the Makefile

Uploading Folder with images to github

As the title states I was uploading my project to github ( https://github.com/siddhartha-ramesh/FilmReview.git ), but I am stuck here. I cant upload a directory called img to github can anyone help me how to do that. I am not using any gui. Can I create a new folder in github.com just the way I can create new files?
This is what that is happening:
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ git remote add origin git#github.com:siddhartha-ramesh/FilmReview.git
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ git push origin master
The authenticity of host 'github.com (204.232.175.90)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,204.232.175.90' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ cd ~
siddhartha#siddhartha-Inspiron-545s ~ $ cd .ssh
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ ssh-keygen -t rsa -C "siddhartharamesh#gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/siddhartha/.ssh/id_rsa): key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in key.
Your public key has been saved in key.pub.
The key fingerprint is:
#key here
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ cd /home/siddharhta/.ssh
bash: cd: /home/siddharhta/.ssh: No such file or directory
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ cd /home/
siddhartha#siddhartha-Inspiron-545s /home $ cd *
siddhartha#siddhartha-Inspiron-545s ~ $ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
siddhartha#siddhartha-Inspiron-545s ~ $ cd ..
siddhartha#siddhartha-Inspiron-545s /home $ ls
siddhartha
siddhartha#siddhartha-Inspiron-545s /home $ cd siddhartha/
siddhartha#siddhartha-Inspiron-545s ~ $ cd .ssh
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ ls
key key.pub known_hosts
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ cat key
-----BEGIN RSA PRIVATE KEY-----
-----END RSA _________________
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ ls -a
. .. key key.pub known_hosts
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ cat key.pub
ssh-rsa
#key here
siddhartha#siddhartha-Inspiron-545s ~/.ssh $ cd ..
siddhartha#siddhartha-Inspiron-545s ~ $ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
siddhartha#siddhartha-Inspiron-545s ~ $ cd Desktop/
siddhartha#siddhartha-Inspiron-545s ~/Desktop $ ls
Aptana_Studio_3 C_C++ Codes key Untitled Folder WS
siddhartha#siddhartha-Inspiron-545s ~/Desktop $ cd Untitled\ Folder/
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ ls
film_review
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ git remote add origin git#github.com:siddhartha-ramesh/FilmReview.git
fatal: remote origin already exists.
siddhartha#siddhartha-Inspiron-545s ~/Desktop/Untitled Folder $ git push origin master
To git#github.com:siddhartha-ramesh/FilmReview.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:siddhartha-ramesh/FilmReview.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
If you have your folder with your files (pictures in this case) in your local repo (cloned of your github repo), all you need to do to see that folder on GitHub is:
cd /path/to/that/folder
git add .
git commit "add folder with pictures"
git push
# or, if this is your first push:
git push -u origin master
In other words, you add all the files in that folder, and push them.
Instead of trying to add a remote, clone your GitHub repo first, add content in the local clone and push.
Don't use ssh first, use a simpler url based on https, and your login/password:
git clone https://siddhartha-ramesh#github.com/siddhartha-ramesh/FilmReview
cd FilmReview
git config user.name siddhartha-ramesh
git config user.email (your email address used on GitHub)
# add your files
git add .
git commit -m "Add folder"
git push -u origin master
# the next push can be simply 'git push'
GitHub's UI in this respect has not changed in all of these years. If you want to add directories via the GitHub UI, you have to do this:
Select Add file.
Don't pick upload file like you'd think. Instead, select "Create new file".
Up at the top where it says your project name, you should see "Name your file...". Instead of typing the name, type the directory name you're wanting to add and instead of hitting enter, type "/".
Now you need to either add a real file to that directory or just create a fake file name with fake contents. In my case, I just titled it "test.js" with "test" on line 1.
Now, you need to commit the file.
GitHub will create a directory and will upload your new file.
Now if you want, you can delete the test file and your new directory will remain.
Caveat: I'm not sure if you can create a nested directory two levels deep using the "/" trick or not.