I have found a way to upload an SSH key to my GitHub account with command line, but there is small problem.

I am able to do this with following command:

curl -u "user:pass" --data '{"title":"test-key","key":"ssh-rsa Aaa"}'

https://api.github.com/user/keys

But I am using this in Chef to add my nodes' keys to my GitHub account:

curl -u "user:pass" --data '{"title":"test-key","key":"`cat ~/.ssh/id_rsa.pub`"}' https://api.github.com/user/keys

but it is giving error.

What could be the reason?

share|improve this question
    
You'll probably want to put the cat command in $() so that it gets ran rather than literally putting that string of text in as your SSH key. – Bratchley Jul 21 '16 at 8:06
    
On mobile so I can't type it all out but you'll probably have to change your quotes as well. – Bratchley Jul 21 '16 at 8:07
    
You could also used stdin instead of an option value. unix.stackexchange.com/questions/77588/… – Bratchley Jul 21 '16 at 8:10
    
i am using this is chef so i want a generic way to do this – amit singh Jul 21 '16 at 8:12
up vote 1 down vote accepted

The cat command results must be expanded using command substitution.

The syntax for bash is:

curl -u "user:pass" --data '{"title":"test-key","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys

You can also use a classic backtick notation:

curl -u "user:pass" --data '{"title":"test-key","key":"'`cat ~/.ssh/id_rsa.pub`'"}' https://api.github.com/user/keys
share|improve this answer
    
i am using this in chef to update my node's ssh -key in github. i am editing this in my question – amit singh Jul 21 '16 at 8:21
    
you first option did the trick, thnks very much – amit singh Jul 21 '16 at 8:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.