Git, vagrant (lucid 32), mountain lion, Permission denied - ssh

I'm having a similar problem to this:
Permission denied (publickey). fatal: The remote end hung up unexpectedly while pushing back to git repository
But I suspect it might be more complicated because I am running vagrant on a mac (mountain lion) and I am having this "Permission Denied" issue that I wasn't having in Snow Leopard.
I set up git on my mac (mountain lion) with ssh key, it works.
I set up vagrant (lucid32 box) and set up a new ssh key (once I ssh'ed into vagrant):
cd ~/.ssh
ssh-keygen -t rsa -C "myemail#mail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): [just hit enter]
Enter same passphrase again: [just hit enter]
Then I added the ssh key to my github repo (note: was having problems with pbcopy/xclip so I just used vi and copy-pasted)
vagrant#lucid32:~$ cd /vagrant/
vagrant#lucid32:/vagrant$ git push -u origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
So, now I have two ssh keys in my github repo:
- My Mac key (works, can commit to my non-vagrant repo from my mac)
- My vagrant key (does not work, cannot ssh into vagrant and commit my repo from my vagrant box)

Are you trying to push to a github repo?
If so, you're going to need to add the SSH key of the vagrant VM to your account on Github under account settings.
Keep in mind, a Vagrant VM is essentially a "different" machine than your local machine, so it will have a different SSH key.
See this github article on working with SSH keys

Mine started working, I followed this advice:
Unable to Git-push master to Github
And added a config file to my ~/.ssh folder. Not it works but I'm not sure if why that helps?

Related

Gitlab SSH Key | must the ssh have the same username as gitlab account

Problem
Does the 'user#host' of the id_rsa.pub need to match with the actual machine username - host and then with the username in Gitlab?
Example:
Gitlab username name: #john.doe
Ubuntu Machine hostname command hostname: JOHNDOE
Ubuntu username: mark
Username in the id_rsa.pub: ...fsdfsdfsdfsd mark#JOHNDOE
So as you can see, my user in Ubuntu is mark and the ssh rsa key generated has a mark#JOHNDOE as last domain. But should it be john.doe#JOHNDOE instead (both in Ubuntu user and in the ssh pub key)?
And let's say that for some reason I cannot change the user in my Ubuntu machine.
I honestly think the answer is no and the issue is on my user in Gitlab that has some missing permissions or some network related problem, and I'm just paranoid but just to make sure that is not related with the ssh keys.
I think the ssh key just need to match the one in Gitlab and the username in the key has nothing to do (because actually, you can change it with command -C "john.doe#JOHNDOE" which is a Comment and anyway it still gives me errors. But again I have the doubt is ALSO the username of the Ubuntu must be john.doe
Command run / Troubleshot
OS: Ubuntu 18.04.6 LTS on Windows 10 x86_64 (WSL)
I need to connect via VPN (all other https services works via Browser so it should be fine)
Creating ssh
ssh-keygen -t rsa -b 2048
Add SSH
cat ~/.ssh/id_rsa.pub
# Then copy the key to gitlba key - etc..
Also try do
eval $(ssh-agent -s)
ssh-add -D
ssh-add ~/.ssh/id_rsa.pub
Error
Do a git clone
Please make sure you have the correct access rights and the repository exists.
Connecting
ssh -T git#gitlab.example.com
banner exchange: Connection to [here the IP but removed] port 22: Connection timed out
Ok so the problem is the VPN software that I used.
As #Raya pointed out the answer to my question is:
No, the user in the ssh public key does not matter
As soon as I changed the VPN it start to work therefore the problem was Network related
Will auto-post the answer and mark as accepted, but won't close the question so if anyone has better information can add it.

DigitalOcean Permission denied (publickey) when adding new ssh keys to an existing droplet?

Having issue adding new ssh keys to an existing droplet on Digital Ocean Ubuntu VM.
SSH key is added via Digial Ocean portal via browser.
When added SSH key first time from local Ubuntu machine it is working fine.
Next time trying to add SSH from MacOS machine, and unable to login even though 2nd SSH key was added successfully, and keep getting Permission denied (publickey) error.
Checking on the remote Ubuntu droplet nano /etc/ssh/sshd_config can see PubkeyAuthenthication yes
There seem to be an issue with Digital Ocean web portal when adding 2nd SSH key. The portal show there are 2 SSH keys (Settings\Security\SSH keys).
However, checking authorized_keys file (nano .ssh/authorized_keys), only the 1st SSH key was there and the 2nd SSH key was not found.
Work a round fix was to login the Ubuntu server/droplet (using the working local Ubuntu machine for my case), and manually add 2nd SSH key (for MacOS machine) to authorized_keys file.
Server/Droplet Ubuntu:
nano .ssh/authorized_key
MacOS local machine:
cat .ssh/id_ed25519.pub ( I used ed25519 type in this instance, change to whatever yours pub key is).
Paste the SSH pub key to authorized_key file.
Reload ssh on Ubuntu server/droplet: systemctl reload ssh
make sure that the content of your public key corresponds to that in ~/.ssh/authorized_keys

SSH deploy from Bitbucket. Disable passphrase?

So basically my setup is that i'm creating an ssh pair on my remote server, then copying the pub key to bitbucket, and my server's authorized_keys file.
I'm still getting permission denied when I run my deploy on Bitbucket.
Any SSH key you use in Pipelines should not have a passphrase.
I'm assuming this has something to do with it, even tho i created the ssh pair with a blank password, my sshd_config file has:
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
Should I change this to yes?
Bitbucket's documentation says I should ssh-copy-id -i my_ssh_key user#host, but that doesn't make sense to me since all ssh gen is either happening on the remote or in Bitbucket itself.
Have no idea why this isn't clearer.
Edit: here's the error on the bitbucket build:
+ cat ./deploy.sh | ssh username#remote.com
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: Permanently added the RSA host key for IP address ‘XXX.XXX.XX.XX’ to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
Here are some values of my sshd_config:
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
Ok, got it. For some reason, i had my ssh logic backwards. I re-created the ssh key pair in Bitbucket, added the public key to my remote server's ~/ssh/authorized_keys file, AND ... I assured that the permissions of that file was set to 600. Once I fixed that permission, I had my first successful build. Hope this helps someone.

Raspberry - can't clone from bitbucket using SSH

Didn't thought I will be stuck here.
Got .ssh key on my win machine: [my user]/.ssh/mybitbucket
Able to clone from bitbucket.org with it
Need to clone project to RaspberryPi
Copy-pasted mybitbucket and mybitbucket.pub to ~/.ssh on Raspberry
Then git clone git#bitbucket.org:[username]/my_utils.git
and got this:
Failed to add the host to the list of known hosts
(/home/pi/.ssh/known_hosts).
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any help?
Also added mybitbucket.pub to authorized_keys, but can't connect to Raspberry from Xshell with SSH key for reason unknown to me. Just choosing my key from options, click OK, the connection window blinks and nothing happens
EDIT:
Just for an experiment I generated a new key on Raspberry and added it to bitbucket - that worked. Though how to add existing keys?
Failed to add the host to the list of known hosts
Also added mybitbucket.pub to authorized_keys, but can't connect to Raspberry
I am 98% sure both problems are the result of one misconfiguration: files in /home/pi/.ssh belong to user root. To fix:
sudo chown -R pi /home/pi/.ssh
chmod -R u=rw,go= /home/pi/.ssh
After that copy relevant parts of [my user]/.ssh/config to /home/pi/.ssh/config.

ssh authentication fails after ssh-agent terminates

Backstory: currently running Arch Linux and attempting to authenticate into Github using SSH keys. I have openssh 7.1p1-1 installed as well as git 2.6.4-1.
Problem: After the ssh-agent terminates (system reboot or shell closure), I get the "Permission Denied (publickey)" message when attempting to connect to git using:
ssh -vT git#github.com
Any ideas as to why my identity does not persist? Do I have to add anything special to the ~/.ssh/config or /etc/ssh/ssh_config files?
Thank you for any help you can provide.
After ssh-agent is gone, ssh is no longer aware that id_github exists, so it never tries authenticating with that key. If you want to force ssh to always use that key for github.com, you can add this to ~/.ssh/config:
Host github.com
IdentityFile ~/.ssh/id_github
User git # Handy addition so you can skip the username part in Github URLs