Git access fails in EC2 instance startup script (Ubuntu)Git Daemon on linux?Git and Amazon EC2 public key deniedHow to keep groups when pulling with gitUnable to do a git pull - related to upgrade from Ubuntu 11.10 to 12.04?Setup git on an Internal Server [Ubuntu]In Amazon EC2, what's the best way to clone a private github repository on boot?How to deploy in amazon ec2 through bitbucketEC2 instance (Ubuntu) suddenly got very sluggishAnsible can't git clone from enterprise git serverGit push fails in copied VM - stumped

Prime sieve in Python

How do I handle a table mixing up the DM and the players' roles too often?

Silly doubt about tidal effects and Einstein Field Equations

Trainee keeps missing deadlines for independent learning

Why are < or > required to use /dev/tcp

Can White Castle?

Is it illegal to withhold someone's passport and green card in California?

Can Ogre clerics use Purify Food and Drink on humanoid characters?

Do I have to explain the mechanical superiority of the player-character within the fiction of the game?

Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?

How large would a mega structure have to be to host 1 billion people indefinitely?

How much will studying magic in an academy cost?

Do I need a shock-proof watch for cycling?

What does it mean to "control target player"?

What's currently blocking the construction of the wall between Mexico and the US?

Did the CIA blow up a Siberian pipeline in 1982?

.NET executes a SQL query and Active Monitor shows multiple rows blocking each other

Parameterize chained calls to a utility program in Bash

Why don't countries like Japan just print more money?

How many children?

Cut the gold chain

Who are the remaining King/Queenslayers?

When can you leave off “le/la” to say “it” in French?

What's the difference between a deep fryer and a chip pan?



Git access fails in EC2 instance startup script (Ubuntu)


Git Daemon on linux?Git and Amazon EC2 public key deniedHow to keep groups when pulling with gitUnable to do a git pull - related to upgrade from Ubuntu 11.10 to 12.04?Setup git on an Internal Server [Ubuntu]In Amazon EC2, what's the best way to clone a private github repository on boot?How to deploy in amazon ec2 through bitbucketEC2 instance (Ubuntu) suddenly got very sluggishAnsible can't git clone from enterprise git serverGit push fails in copied VM - stumped






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















I am creating an ec2 instance from an AMI using



aws ec2 run-instances [lots of arguments] --user-data file://my_sh_file.sh


my_sh_file.sh looks like this:



su ubuntu # fails with or without this
cd /home/ubuntu/my_working_dir
git pull origin master
. app_startup_script.sh


Git is failing to connect with this error log (from /var/log/cloud-init-output.log):



Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


If I log in myself (as ubuntu) and call git pull it works fine.



I guess that either (a) su ubuntu isn't working, or (b) (this seems less likely) that the ssh config isn't loaded at this point in the boot sequence... but I'm stumped. Help?










share|improve this question



















  • 1





    How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

    – Lucas Ramage
    Jun 5 at 15:31











  • git remote -v please. By the way, do you use ssh-agent?

    – kubanczyk
    Jun 5 at 18:00












  • I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

    – Omroth
    Jun 5 at 18:16












  • ssh key and config is in home/ubuntu/.ssh

    – Omroth
    Jun 5 at 18:17

















4















I am creating an ec2 instance from an AMI using



aws ec2 run-instances [lots of arguments] --user-data file://my_sh_file.sh


my_sh_file.sh looks like this:



su ubuntu # fails with or without this
cd /home/ubuntu/my_working_dir
git pull origin master
. app_startup_script.sh


Git is failing to connect with this error log (from /var/log/cloud-init-output.log):



Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


If I log in myself (as ubuntu) and call git pull it works fine.



I guess that either (a) su ubuntu isn't working, or (b) (this seems less likely) that the ssh config isn't loaded at this point in the boot sequence... but I'm stumped. Help?










share|improve this question



















  • 1





    How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

    – Lucas Ramage
    Jun 5 at 15:31











  • git remote -v please. By the way, do you use ssh-agent?

    – kubanczyk
    Jun 5 at 18:00












  • I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

    – Omroth
    Jun 5 at 18:16












  • ssh key and config is in home/ubuntu/.ssh

    – Omroth
    Jun 5 at 18:17













4












4








4








I am creating an ec2 instance from an AMI using



aws ec2 run-instances [lots of arguments] --user-data file://my_sh_file.sh


my_sh_file.sh looks like this:



su ubuntu # fails with or without this
cd /home/ubuntu/my_working_dir
git pull origin master
. app_startup_script.sh


Git is failing to connect with this error log (from /var/log/cloud-init-output.log):



Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


If I log in myself (as ubuntu) and call git pull it works fine.



I guess that either (a) su ubuntu isn't working, or (b) (this seems less likely) that the ssh config isn't loaded at this point in the boot sequence... but I'm stumped. Help?










share|improve this question
















I am creating an ec2 instance from an AMI using



aws ec2 run-instances [lots of arguments] --user-data file://my_sh_file.sh


my_sh_file.sh looks like this:



su ubuntu # fails with or without this
cd /home/ubuntu/my_working_dir
git pull origin master
. app_startup_script.sh


Git is failing to connect with this error log (from /var/log/cloud-init-output.log):



Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


If I log in myself (as ubuntu) and call git pull it works fine.



I guess that either (a) su ubuntu isn't working, or (b) (this seems less likely) that the ssh config isn't loaded at this point in the boot sequence... but I'm stumped. Help?







ubuntu amazon-web-services amazon-ec2 git






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 5 at 18:21









Lucas Ramage

12310




12310










asked Jun 5 at 15:21









OmrothOmroth

354




354







  • 1





    How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

    – Lucas Ramage
    Jun 5 at 15:31











  • git remote -v please. By the way, do you use ssh-agent?

    – kubanczyk
    Jun 5 at 18:00












  • I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

    – Omroth
    Jun 5 at 18:16












  • ssh key and config is in home/ubuntu/.ssh

    – Omroth
    Jun 5 at 18:17












  • 1





    How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

    – Lucas Ramage
    Jun 5 at 15:31











  • git remote -v please. By the way, do you use ssh-agent?

    – kubanczyk
    Jun 5 at 18:00












  • I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

    – Omroth
    Jun 5 at 18:16












  • ssh key and config is in home/ubuntu/.ssh

    – Omroth
    Jun 5 at 18:17







1




1





How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

– Lucas Ramage
Jun 5 at 15:31





How are you cloning the git repo to begin with? That response suggests it may be an issue with the ssh key.

– Lucas Ramage
Jun 5 at 15:31













git remote -v please. By the way, do you use ssh-agent?

– kubanczyk
Jun 5 at 18:00






git remote -v please. By the way, do you use ssh-agent?

– kubanczyk
Jun 5 at 18:00














I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

– Omroth
Jun 5 at 18:16






I don't use ssh agent. Git remote: origin ec2-user@[ip of git server]:[repo name] (fetch) origin ec2-user@[ip of git server]:[repo name] (push) I agree it sounds like an access problem but when I log in myself and just call git pull origin master it works fine.

– Omroth
Jun 5 at 18:16














ssh key and config is in home/ubuntu/.ssh

– Omroth
Jun 5 at 18:17





ssh key and config is in home/ubuntu/.ssh

– Omroth
Jun 5 at 18:17










1 Answer
1






active

oldest

votes


















3














The way you use sudo Isn’t correct.



First of all it should be sudo -u ubuntu not just sudo ubuntu. However even then it wouldn't work.



When you run sudo it spawns a new shell or if a command is given it runs that command under the ubuntu user. In your case sudo -u ubuntu doesn’t have a command to run and because it is in non-interactive mode it won’t spawn a shell either. It simply exits.



The following lines - cd and git - then run in the context of the UserData script, not under ubuntu user, that's why it fails.



You can do this for example:



sudo -u ubuntu sh -c "cd /home/...; git pull ...; ./app.sh"


That will run all the commands under the ubuntu user.



Hope that helps :)






share|improve this answer

























  • Thank you :) Perfect.

    – Omroth
    Jun 6 at 8:35













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970244%2fgit-access-fails-in-ec2-instance-startup-script-ubuntu%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









3














The way you use sudo Isn’t correct.



First of all it should be sudo -u ubuntu not just sudo ubuntu. However even then it wouldn't work.



When you run sudo it spawns a new shell or if a command is given it runs that command under the ubuntu user. In your case sudo -u ubuntu doesn’t have a command to run and because it is in non-interactive mode it won’t spawn a shell either. It simply exits.



The following lines - cd and git - then run in the context of the UserData script, not under ubuntu user, that's why it fails.



You can do this for example:



sudo -u ubuntu sh -c "cd /home/...; git pull ...; ./app.sh"


That will run all the commands under the ubuntu user.



Hope that helps :)






share|improve this answer

























  • Thank you :) Perfect.

    – Omroth
    Jun 6 at 8:35















3














The way you use sudo Isn’t correct.



First of all it should be sudo -u ubuntu not just sudo ubuntu. However even then it wouldn't work.



When you run sudo it spawns a new shell or if a command is given it runs that command under the ubuntu user. In your case sudo -u ubuntu doesn’t have a command to run and because it is in non-interactive mode it won’t spawn a shell either. It simply exits.



The following lines - cd and git - then run in the context of the UserData script, not under ubuntu user, that's why it fails.



You can do this for example:



sudo -u ubuntu sh -c "cd /home/...; git pull ...; ./app.sh"


That will run all the commands under the ubuntu user.



Hope that helps :)






share|improve this answer

























  • Thank you :) Perfect.

    – Omroth
    Jun 6 at 8:35













3












3








3







The way you use sudo Isn’t correct.



First of all it should be sudo -u ubuntu not just sudo ubuntu. However even then it wouldn't work.



When you run sudo it spawns a new shell or if a command is given it runs that command under the ubuntu user. In your case sudo -u ubuntu doesn’t have a command to run and because it is in non-interactive mode it won’t spawn a shell either. It simply exits.



The following lines - cd and git - then run in the context of the UserData script, not under ubuntu user, that's why it fails.



You can do this for example:



sudo -u ubuntu sh -c "cd /home/...; git pull ...; ./app.sh"


That will run all the commands under the ubuntu user.



Hope that helps :)






share|improve this answer















The way you use sudo Isn’t correct.



First of all it should be sudo -u ubuntu not just sudo ubuntu. However even then it wouldn't work.



When you run sudo it spawns a new shell or if a command is given it runs that command under the ubuntu user. In your case sudo -u ubuntu doesn’t have a command to run and because it is in non-interactive mode it won’t spawn a shell either. It simply exits.



The following lines - cd and git - then run in the context of the UserData script, not under ubuntu user, that's why it fails.



You can do this for example:



sudo -u ubuntu sh -c "cd /home/...; git pull ...; ./app.sh"


That will run all the commands under the ubuntu user.



Hope that helps :)







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 5 at 22:11

























answered Jun 5 at 20:53









MLuMLu

10.6k22546




10.6k22546












  • Thank you :) Perfect.

    – Omroth
    Jun 6 at 8:35

















  • Thank you :) Perfect.

    – Omroth
    Jun 6 at 8:35
















Thank you :) Perfect.

– Omroth
Jun 6 at 8:35





Thank you :) Perfect.

– Omroth
Jun 6 at 8:35

















draft saved

draft discarded
















































Thanks for contributing an answer to Server Fault!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970244%2fgit-access-fails-in-ec2-instance-startup-script-ubuntu%23new-answer', 'question_page');

);

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







Popular posts from this blog

How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

Why did Thanos need his ship to help him in the battle scene?Which actor plays Thanos in the Avengers mid-credits scene?Are there economic implications portrayed in comics where the buildings and cities are ruined almost daily?Old X-Men comic where team travels to alien world with a ring-like sun that needs recharging?Why does Ego need help sleeping?Is there an objective answer to who “the strongest Avenger” is?How did Banner get unstuck?Why did Thanos get hit?How did Thanos (or anyone) know the Infinity Stones would give him this power?Did Thanos leave Eitri alive for his after-sales service?In Avengers 1, why does Thanos need Loki?