Git clone using ssh from a repository in AWS EC2?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
On my EC2 instance I create a rails project (my_app) and then a repository of it :
deploy@ip-ec2: ~/my_app$ git init
(then git add-A, then git commit -m "initialized", and everything is ok)
also in this server add the public key of my local machine: id_rsa.pub, to the file authorized_keys in server side.
Now in local machine, I want to clone the created repository that is in the ec2:
local@machine:~/repos$ sudo git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
output in local machine:
Clonar en «my_app»...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What I am missing? Should I have to change some permission in server project?
thanks in advanced
git amazon-web-services amazon-ec2 ssh git-clone
add a comment |
On my EC2 instance I create a rails project (my_app) and then a repository of it :
deploy@ip-ec2: ~/my_app$ git init
(then git add-A, then git commit -m "initialized", and everything is ok)
also in this server add the public key of my local machine: id_rsa.pub, to the file authorized_keys in server side.
Now in local machine, I want to clone the created repository that is in the ec2:
local@machine:~/repos$ sudo git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
output in local machine:
Clonar en «my_app»...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What I am missing? Should I have to change some permission in server project?
thanks in advanced
git amazon-web-services amazon-ec2 ssh git-clone
add a comment |
On my EC2 instance I create a rails project (my_app) and then a repository of it :
deploy@ip-ec2: ~/my_app$ git init
(then git add-A, then git commit -m "initialized", and everything is ok)
also in this server add the public key of my local machine: id_rsa.pub, to the file authorized_keys in server side.
Now in local machine, I want to clone the created repository that is in the ec2:
local@machine:~/repos$ sudo git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
output in local machine:
Clonar en «my_app»...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What I am missing? Should I have to change some permission in server project?
thanks in advanced
git amazon-web-services amazon-ec2 ssh git-clone
On my EC2 instance I create a rails project (my_app) and then a repository of it :
deploy@ip-ec2: ~/my_app$ git init
(then git add-A, then git commit -m "initialized", and everything is ok)
also in this server add the public key of my local machine: id_rsa.pub, to the file authorized_keys in server side.
Now in local machine, I want to clone the created repository that is in the ec2:
local@machine:~/repos$ sudo git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
output in local machine:
Clonar en «my_app»...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What I am missing? Should I have to change some permission in server project?
thanks in advanced
git amazon-web-services amazon-ec2 ssh git-clone
git amazon-web-services amazon-ec2 ssh git-clone
asked Nov 23 '18 at 19:25
matQmatQ
144111
144111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you SSh to the EC2 node are you using ssh -i /path/to/key
? To use the private key on the EC2 node, you will need to setup the ssh-agent and forward it via the SSH connection by using -A
switch.
If you run: ssh-add -l
, it should show all keys known to the agent.
$ ssh-add -l
4096 SHA256:xxxxxxxxxxxxxx /home/matt/.ssh/id_rsa (RSA)
If you run this from your EC2 node without forwardng the agent, you will see that the agent is not found, or that there are no known keys.
On your first host, check to see if the agent is running using the above command.
If it is running and had your key, then all you need to do is forward. If you do not have the agent running, you will need start a new instance by simply running ssh-agent
, however this will print some commands you will need to run:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-jZBbs4yRG03w/agent.6708; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16496; export SSH_AGENT_PID;
echo Agent pid 16496;
The simplest way to handle this, is to start the agent and evaluate at the same time with one command:
$ eval `ssh-agent`
Agent pid 16496
Now add your keys, if they are the default path / name:
ssh-add
or
ssh-add /path/to/key
Now you are good to forward the agent to your EC2 node.
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run evalssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?
– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,ssh -A ec2-user@ip
From there, you will still have access to your key,ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452022%2fgit-clone-using-ssh-from-a-repository-in-aws-ec2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you SSh to the EC2 node are you using ssh -i /path/to/key
? To use the private key on the EC2 node, you will need to setup the ssh-agent and forward it via the SSH connection by using -A
switch.
If you run: ssh-add -l
, it should show all keys known to the agent.
$ ssh-add -l
4096 SHA256:xxxxxxxxxxxxxx /home/matt/.ssh/id_rsa (RSA)
If you run this from your EC2 node without forwardng the agent, you will see that the agent is not found, or that there are no known keys.
On your first host, check to see if the agent is running using the above command.
If it is running and had your key, then all you need to do is forward. If you do not have the agent running, you will need start a new instance by simply running ssh-agent
, however this will print some commands you will need to run:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-jZBbs4yRG03w/agent.6708; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16496; export SSH_AGENT_PID;
echo Agent pid 16496;
The simplest way to handle this, is to start the agent and evaluate at the same time with one command:
$ eval `ssh-agent`
Agent pid 16496
Now add your keys, if they are the default path / name:
ssh-add
or
ssh-add /path/to/key
Now you are good to forward the agent to your EC2 node.
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run evalssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?
– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,ssh -A ec2-user@ip
From there, you will still have access to your key,ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
|
show 1 more comment
When you SSh to the EC2 node are you using ssh -i /path/to/key
? To use the private key on the EC2 node, you will need to setup the ssh-agent and forward it via the SSH connection by using -A
switch.
If you run: ssh-add -l
, it should show all keys known to the agent.
$ ssh-add -l
4096 SHA256:xxxxxxxxxxxxxx /home/matt/.ssh/id_rsa (RSA)
If you run this from your EC2 node without forwardng the agent, you will see that the agent is not found, or that there are no known keys.
On your first host, check to see if the agent is running using the above command.
If it is running and had your key, then all you need to do is forward. If you do not have the agent running, you will need start a new instance by simply running ssh-agent
, however this will print some commands you will need to run:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-jZBbs4yRG03w/agent.6708; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16496; export SSH_AGENT_PID;
echo Agent pid 16496;
The simplest way to handle this, is to start the agent and evaluate at the same time with one command:
$ eval `ssh-agent`
Agent pid 16496
Now add your keys, if they are the default path / name:
ssh-add
or
ssh-add /path/to/key
Now you are good to forward the agent to your EC2 node.
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run evalssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?
– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,ssh -A ec2-user@ip
From there, you will still have access to your key,ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
|
show 1 more comment
When you SSh to the EC2 node are you using ssh -i /path/to/key
? To use the private key on the EC2 node, you will need to setup the ssh-agent and forward it via the SSH connection by using -A
switch.
If you run: ssh-add -l
, it should show all keys known to the agent.
$ ssh-add -l
4096 SHA256:xxxxxxxxxxxxxx /home/matt/.ssh/id_rsa (RSA)
If you run this from your EC2 node without forwardng the agent, you will see that the agent is not found, or that there are no known keys.
On your first host, check to see if the agent is running using the above command.
If it is running and had your key, then all you need to do is forward. If you do not have the agent running, you will need start a new instance by simply running ssh-agent
, however this will print some commands you will need to run:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-jZBbs4yRG03w/agent.6708; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16496; export SSH_AGENT_PID;
echo Agent pid 16496;
The simplest way to handle this, is to start the agent and evaluate at the same time with one command:
$ eval `ssh-agent`
Agent pid 16496
Now add your keys, if they are the default path / name:
ssh-add
or
ssh-add /path/to/key
Now you are good to forward the agent to your EC2 node.
When you SSh to the EC2 node are you using ssh -i /path/to/key
? To use the private key on the EC2 node, you will need to setup the ssh-agent and forward it via the SSH connection by using -A
switch.
If you run: ssh-add -l
, it should show all keys known to the agent.
$ ssh-add -l
4096 SHA256:xxxxxxxxxxxxxx /home/matt/.ssh/id_rsa (RSA)
If you run this from your EC2 node without forwardng the agent, you will see that the agent is not found, or that there are no known keys.
On your first host, check to see if the agent is running using the above command.
If it is running and had your key, then all you need to do is forward. If you do not have the agent running, you will need start a new instance by simply running ssh-agent
, however this will print some commands you will need to run:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-jZBbs4yRG03w/agent.6708; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16496; export SSH_AGENT_PID;
echo Agent pid 16496;
The simplest way to handle this, is to start the agent and evaluate at the same time with one command:
$ eval `ssh-agent`
Agent pid 16496
Now add your keys, if they are the default path / name:
ssh-add
or
ssh-add /path/to/key
Now you are good to forward the agent to your EC2 node.
answered Nov 23 '18 at 19:45
Matt ClarkMatt Clark
17.6k104795
17.6k104795
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run evalssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?
– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,ssh -A ec2-user@ip
From there, you will still have access to your key,ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
|
show 1 more comment
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run evalssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?
– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,ssh -A ec2-user@ip
From there, you will still have access to your key,ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
excuse me my english is not good, the command ssh-add -l must be run in the ec2 or in local machine? and to the first question, yes i connect to ec2 like this ssh -i /path/mykey.pem ...
– matQ
Nov 23 '18 at 20:09
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
The agent will run local, but will then be forwarded to the EC2 node. So first local, then remote.
– Matt Clark
Nov 23 '18 at 20:10
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run eval
ssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?– matQ
Nov 23 '18 at 20:17
ok i run in local : ssh-add -l and returns 4096 SHA256:uQ.... , then run eval
ssh-agent
and return Agent pid 5555 then in the folder where is my ec2 key (~/aws/mykey.pem) run ssh-add is that correct?– matQ
Nov 23 '18 at 20:17
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,
ssh -A ec2-user@ip
From there, you will still have access to your key, ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
If ssh-add -l has your key listed, then all you need to do is SSH to your EC2 node using -A,
ssh -A ec2-user@ip
From there, you will still have access to your key, ssh-add -l
– Matt Clark
Nov 23 '18 at 20:29
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
bus how I use ssh -A in git clone? this is the command I try: git clone ssh://deploy@ec2-01-007-53-134.xx-east-1.compute.amazonaws.com/~/my_app
– matQ
Nov 23 '18 at 20:38
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452022%2fgit-clone-using-ssh-from-a-repository-in-aws-ec2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown