We want to remove ads from the website, but we need your help.
Please donate some of your computer power to running our website.

23. February 2017

Automate your ssh or git clone from inside Docker

Solution to automating any ssh command is to avoid having to type yes to all the various questions exposed. For this post I will limit myself to the fact that you have the keys inside your Docker. If you burnt your precious ssh keys into image which is bad (ADD command), or added via volume mapping when running a docker (-v flag) does not matter as long as you know where they are.
Once you are in docker you are logged in as root (by default in most cases). To avoid this you can be logged in as any other user, but then just replace root with ~ in below examples.
Common errors which you will face are:

# Create .ssh directory in your home
mkdir /root/.ssh
# Apply proper permissions to directory
chmod 0700 /root/.ssh

# Create entry of your domain-name in the
ssh-keyscan example.com > /root/.ssh/known_hosts

# Copy both private and public key into your .ssh
cp id_rsa /root/.ssh/id_rsa
cp id_rsa.pub /root/.ssh/id_rsa.pub

# Now you can do a git clone or ssh without that
# strange confirmation questions and without disabling
# strict key checking
git clone git@example.com:somegroup/somerepo.git
ssh user@example.com

Newest from this category: