Most of the answers given here do not explain the details for the most basic usage.
After you have setup a server (in this case a linux
server) in the cloud, you connect to it using ssh from the terminal.
From your computer, add the private key dyson-ubuntu-vm.pem
which is given to you by your cloud services provider such as Azure, AWS etc to your .ssh configuration on your local machine like this:
Copy the .pem
file to the /home/ssenyonjo/.ssh
folder, then open /home/ssenyonjo/.ssh/config
file and add the following entry:
Host 20.85.213.44
HostName 20.85.213.44
User Dyson
IdentityFile /home/ssenyonjo/.ssh/dyson-ubuntu-vm.pem
IdentitiesOnly yes
Now from your terminal, access the cloud linux server like so:
ssh Dyson@20.85.213.44
When that works, create a git project on the cloud server like so:
Dyson@dyson-ubuntu-vm:~/projects$ git init --bare s2
Now come back to your local machine and clone that empty repository like so:
ssenyonjo@ssenyonjo-pc:~/Projects/mastering-git$ git clone ssh://Dyson@20.85.213.44/home/Dyson/projects/s2
If you see an error that looks something like: fatal: Could not read from remote repository
, It means you're accessing the wrong folder. Ensure you have outlined the right path from the root to the created repository.
If you dont want to setup a config file but want to access the ssh server that requires a key, you can use below command:
GIT_SSH_COMMAND='ssh -i ~/Projects/aws/keys/aws_ubuntu.pem' git clone ssh://ubuntu@15.207.99.158/home/ubuntu/projects/mastering-git/rand
You can export the command to continue using it for other tasks like git push
and git pull
export GIT_SSH_COMMAND='ssh -i ~/Projects/aws/keys/aws_ubuntu.pem'
See: https://stackoverflow.com/a/29754018/10030693
-i
option likessh
does.git config core.sshCommand 'ssh -i private_key_file'
. See my answer below