-1

I'm looking to add github to known_hosts for the deploy user when the command is ran by the root user.

The command would be :

ssh -T -o "StrictHostKeyChecking no" git@github.com

Using cloudinit, it runs initially with the root user, so this command in the cloudinit script will only allow the root user.

This is not tied cloudinit specifically, but is there a way/option to specify which user is running a specific ssh command ?

Ben
  • 113
  • 1
  • 9
  • What is the problem you are actually trying to solve that is caused by running that command as root ? – user9517 Sep 03 '16 at 12:53
  • @Iain if you run the command when you're 'root', 'deploy' won't be allowed to reach git. I'd have to login to the server being deploy and run the command – Ben Sep 03 '16 at 12:57
  • 2
    Just as a side note: `-o "StrictHostKeyChecking no"` effectively disables ALL security of OpenSSH and opens your connection up to man-in-the-middle attacks. It is very careless to use this option and you shouldn't do that. You can find the SSH host key fingerprints for GitHub here: https://help.github.com/articles/what-are-github-s-ssh-key-fingerprints/ – aef Sep 03 '16 at 13:08
  • @aef yep it sounds weak to use it so. thx for the hint, I'll surely look into it – Ben Sep 03 '16 at 13:19
  • Google is your friend https://www.google.co.uk/#q=linux+run+command+as+different+user, see bullet point 2 [here](https://serverfault.com/help/how-to-ask) too – user9517 Sep 03 '16 at 13:22
  • @Iainyep sorry i lack of understanding the specific problem I have sometimes, then not finding the solution with the correct keywords – Ben Sep 03 '16 at 13:24

1 Answers1

2

To run a command as a different user you can use su(1) or sudo(1) e.g.

su - someuser ssh -T -o "StrictHostKeyChecking no" git@github.com

or similar.

user9517
  • 115,471
  • 20
  • 215
  • 297