Posts Tagged ssh
I’m keeping my projects privately on gitlab.com and want to use for some of my golang packages standard “go get” command instead of using git clone/pull. When I’m trying to use standard commands I’m getting the error
go get gitlab.com/bykovme/my_package_here # cd .; git clone https://gitlab.com/bykovme/my_package_here.git /home/bykov/gopath/src/gitlab.com/bykovme/my_package_here Cloning into '/home/bykov/gopath/src/gitlab.com/bykovme/my_package_here'... fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
As I’m using SSH keys to access the git repository, the following command solves the issue giving possibility to use standard go packages commands
git config --global url."firstname.lastname@example.org:".insteadOf "https://gitlab.com/"
You can check if it was applied using the following command
The output of the command above should be like the text below
[url "email@example.com:"] insteadOf = https://gitlab.com/
go get gitlab.com/bykovme/my_package_here
is working now.
PS. The same solution is working for github.com
If you came to this page then probably you have different repositories on bitbucket or guthub and you are trying to work with them using SSH keys from the same Mac.
Do the following
1. Go to the folder ~/.ssh/ (create it if it does not exist yet (mkdir .ssh)) and create new ssh key (do not touch existing id_rsa & id_rsa.pub)
$ cd ~/.ssh/ $ ssh-keygen -f ~/.ssh/key_name_here -C "key_name_here"
it will ask you for passphrase, you can leave it empty. This command will generate private and public keys: “key_name_here” and “key_name_here.pub”
2. Create the file “config” in the same folder (> config) and edit it with your favourite command line editor
Host key_name_here HostName bitbucket.org IdentityFile ~/.ssh/key_name_here
3. Repeat items 1 & 2 for your every next key giving the key new name and alias
4. When you use it, make sure that you are using alias instead of original host name to specify appropriate key name (it is “key_name_here” in the case above), for example, for bitbucket instead of
git clone firstname.lastname@example.org:your/repository_name_here.git
you should use
git clone git@key_name_here:your/repository_name_here.git