failed to push the branch to the remote repository - visual-studio

Hello I am trying to push an branch in visual studio there is an error :
When I tried the following windows is shown:
and
I have inserted my credentials but without success.
Is it other way o solve this issue?

You might as well using the git cli.
First you need to create an SSH Key.
--- Linux :
ssh-keygen -t rsa -b 4096 -C "yourGitHubMail#youmail.com"
press 'Enter' a a couple of times
after that you should get a success message.
copy your id_rsa.pub
cat ~/.ssh/id_rsa.pub
--- Windows :
Create folder if exists, and create SSH Key
mkdir /Users/username/.ssh && cd /Users/username/.ssh
ssh-keygen -t rsa -b 4096 -C "yourGitHubMail#youmail.com"
Copy the code was outputed.
Go to you github page and press 'Settings' => 'SSH and GPG Keys'
Click 'New SSH Key'
in the test area under 'Key', paste in your SSH key.

You shoul generate an application password (access token) in GitHub and filling it in instead of your password and it will works ! Doc here

Related

connect to gitlab project using ssh key

Please i added an ssh key on gitlab (public_rsa).
My problem is that I am still asked for my gitlab password and passphrase when i tried to push a branch on repository. My understanding was that after I set up this SSH key, I would no longer have to do that.
ssh-keygen -t rsa -b 4096 -C "gregory#gmail.com" -f $HOME/.ssh/id_rsa_specific
If someone can help to give an explanation i would appreciate it.
Tell me if im not clear .
Thank you.
I see you listed the command that generates the rsa key. You didn't mention if you placed that key in Gitlab or where.
I would first double check that you have copied and pasted the contents of $HOME/.ssh/id_rsa_specific into your Gitlab accounts settings >> ssh keys.
https://docs.gitlab.com/ee/ssh/#adding-an-ssh-key-to-your-gitlab-account
Then I would try checking the ssh key by running the following command in a terminal:
ssh -T git#gitlab.com
https://docs.gitlab.com/ee/ssh/#testing-that-everything-is-set-up-correctly

How to use the GitBash to clone data with ssh (windows 10 environment)

What can I solve this problem?
when I wanted to connect my personal GitLab account, I got an error message like the following picture
### shell script
git clone git#gitlab.com:<username>/test1.git
GitLab server-side
Clone ssh address
PS: I have checked and found some reference from StackOverflow but unfortunately it isn't okay for me
1.git clone through ssh
2.SSH and Git Clone
3.git clone with ssh issue
I have found a great reference but sorry for Mandarin website, however, I can use my way to share how to deal with this issue.
Step 1:
ls -al ~/.ssh
Step 2:
ssh-keygen
(using enter key for default value)
Step 3: To setup config file
vim /c/Users/Willie/.ssh/config
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa
Step 4:
git clone git#gitlab.com:<username>/test2.git
Step 5:
When you finished Step 4
1.the test2.git file will be download done
2.you will get the new file(known_hosts) in the ~/.ssh
PS: I create the id_rsa and id_rsa.ub by myself and I deliver it to the Gitlab server. using both keys to any client-sides(windows and Linux).
Check first if you do have a ~/.ssh/id_rsa private key/~/.ssh/id_rsa.pub public key.
If so, check your private key: if it has 70 chars per line, try and regenerate with the old PEM format:
ssh-keygen -m PEM -t rsa -P "" -f ~/.ssh/id_rsa
(That will override your current key, but if said current key is not working anyway, that should be OK).
Update the public key on GitLab side, and try again, with a simple:
ssh -T git#gitlab.com
Using a config file means not using the user and using a shorter name:
Host gitlab
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa
means: ssh -T gitlab or git clone gitlab:<username>/test2.git will work.

keep getting error /Users/newuser/.ssh/id_rsa: No such file or directory when trying to connect to ssh agent. Any idea what Im doing wrong?

I'm following the github instructions on how to set up ssh key and add it to the ssh agent. However after I input ssh-add -K ~/.ssh/id_rsa into the terminal, I receive this error: /Users/newuser/.ssh/id_rsa: No such file or directory
I set up my ssh key using Enter file in which to save the key (/Users/newuser/.ssh/id_rsa) so I believe its the correct name.
Any help would be appreciated!
I have been following the same instructions and meet the same problem. This is what worked for me:
cd ~/.ssh
ssh-add id_rsa
Enter file in which to save the key (/c/Users/YOURNAME/.ssh/id_rsa): id_rsa
Use the key in id_rsa.pub to add SSH Key
$ ssh -vT git#github.com
Screen will display:
You've successfully authenticated, but GitHub does not provide shell access.

Execute command inside a shell script on a remote machine and get output on local machine

There are similar questions on stackoverflow, but they either don't have an answer or use some language (C#, Python, ...). I'm trying to execute a command on a remote machine using ssh and get the console output back to the local machine. Below is the command I'm having issues:
sshpass -p $password 'find /home/pi/Transmission_Downloads/ -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" \) -newermt "2016-02-01"' user#myserver.com
When I try to execute it inside my script I get "sshpass: Failed to run command: No such file or directory" error.
What I'm trying to achieve: fetch from the server a list of new files downloaded (movies and TV shows) for later on pulling them from the server using rsync.
Is there a way I can achieve this using only password, or do I HAVE TO use public/private keys to access the server?
My local machine is using Ubuntu 14.04 (desktop) and my server is running Raspbian.
Setting up a password less login to your remote machine might be a solution for easily accomplishing the task.
First log in on Sys_A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a#Sys_A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a#A
Now use ssh to create a directory ~/.ssh as user b on Sys_B. (The directory may already exist, which is fine):
a#Sys_A:~> ssh b#B mkdir -p .ssh
b#Sys_B's password:
Finally append a's new public key to b#Sys_B:.ssh/authorized_keys and enter b's password one last time:
a#Sys_A:~> cat .ssh/id_rsa.pub | ssh b#B 'cat >> .ssh/authorized_keys'
b#Sys_B's password:
From now on you can log into Sys_B as b from Sys_A as a without password:
a#Sys_A:~> ssh b#Sys_B
Then you can integrate your command in a bash script, and use ssh without any user interaction.

How to prevent that the password to decrypt the private key has to be entered every time when using Git Bash on Windows?

I've an automatic building service which download from a git private repository.
The problem is that when it tries to clone repository it need to provide the password, because it is not remembered; so because there is no human interaction, it waits forever the password.
How can I force it to remember from id_rsa.pub?
For Windows users, just a note that this is how I set up the Git Bash environment to log me in once when I start it up. I edit my ~/.bashrc file:
eval `ssh-agent`
ssh-add
So when I start Git Bash, it looks like:
Welcome to Git (version 1.7.8-preview20111206)
(etc)
Agent pid 3376
Enter passphrase for /c/Users/starmonkey/.ssh/id_dsa:
Identity added: /c/Users/starmonkey/.ssh/id_dsa (/c/Users/starmonkey/.ssh/id_dsa)
And now I can ssh to other servers without logging in every time.
This answer explains how to get the GitHub username and password to be stored permanently, not the SSH key passphrase.
In Windows, just run
$ git config --global credential.helper wincred
This means that the next time you push, you'll enter your username and password as usual, but they'll be saved in Windows credentials. You won't have to enter them again, after that.
As in, Push to GitHub without entering username and password every time (Git Bash on Windows).
I prefer not to have to type my SSH passphrase when opening new terminals; unfortunately starmonkey's solution requires the password to be typed in for every session. Instead, I have this in my .bash_profile file:
# Note: ~/.ssh/environment should not be used, as it
# already has a different purpose in SSH.
env=~/.ssh/agent.env
# Note: Don't bother checking SSH_AGENT_PID. It's not used
# by SSH itself, and it might even be incorrect
# (for example, when using agent-forwarding over SSH).
agent_is_running() {
if [ "$SSH_AUTH_SOCK" ]; then
# ssh-add returns:
# 0 = agent running, has keys
# 1 = agent running, no keys
# 2 = agent not running
ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ]
else
false
fi
}
agent_has_keys() {
ssh-add -l >/dev/null 2>&1
}
agent_load_env() {
. "$env" >/dev/null
}
agent_start() {
(umask 077; ssh-agent >"$env")
. "$env" >/dev/null
}
if ! agent_is_running; then
agent_load_env
fi
# If your keys are not stored in ~/.ssh/id_rsa or ~/.ssh/id_dsa, you'll need
# to paste the proper path after ssh-add
if ! agent_is_running; then
agent_start
ssh-add
elif ! agent_has_keys; then
ssh-add
fi
unset env
This will remember my passphrase for new terminal sessions as well; I only have to type it in once when I open my first terminal after booting.
I'd like to credit where I got this; it's a modification of somebody else's work, but I can't remember where it came from. Thanks anonymous author!
Update 2019-07-01: I don't think all this is necessary. I now consistently have this working by ensuring my .bash_profile file runs the ssh-agent:
eval $(ssh-agent)
Then I set up an ssh configuration file like this:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo 'AddKeysToAgent yes' >> ~/.ssh/config
If I understand the question correctly, you're already using an authorized SSH key in the build service, but you want to avoid having to type the passphrase for every clone?
I can think of two ways of doing this:
If your build service is being started interactively: Before you start the build service, start ssh-agent with a sufficiently long timeout (-t option). Then use ssh-add (msysGit should have those) to add all the private keys you need before you start your build service. You'd still have to type out all the passphrases, but only once per service launch.
If you want to avoid having to type the passphrases out at all, you can always remove the passphrases from the SSH keys, as described in https://serverfault.com/questions/50775/how-do-i-change-my-private-key-passphrase, by setting an empty new passphrase. This should do away with the password prompt entirely, but it is even less secure than the previous option.
When I tried to push my code, I got the below error:
$ git push origin dev
remote: Too many invalid password attempts. Try logging in through the website with your password.
fatal: unable to access 'https://naushadqamar-1#bitbucket.org/xxxx/xxxx-api.git/': The requested URL returned error: 403
After a few hours of research, I found I need to use the below command:
$ git config --global credential.helper cache
After executing the above command, I got the prompt for entering my GitHub username and password. After providing the correct credentials, I am able to push my code.
The right solution is:
Run the Windows default terminal - cmd and get the directory of your master profile
echo %USERPROFILE%
Run Git Bash in the directory above and create the .bashrc file with the command
echo "" > .bashrc
Open the .bashrc file with your favourite text editor and paste code from GitHub Help into that file:
env=~/.ssh/agent.env
...
COPY WHOLE CODE FROM URL - I can't add it to Stack Overflow because it breaks layout... OMG!
Restart Git Bash and it asks you for your password (only first time) and done. No password bothering again.
You need to create the authorized_keys file under the .ssh folder of the user under which you are going to connect to the repository server. For example, assuming you use username buildservice on repo.server you can run:
cd ~buidservice
mkdir ./ssh
cat id_rsa.pub >> .ssh/authorized_keys
Then you have to check the following things:
That corresponding id_rsa private key is presented in builservice#build.server:~/.shh/id_rsa.
That fingerprint of repo.server is stored in the buildservice#build.server:~/.ssh/known_hosts file. Typically that will be done after the first attempt of ssh to connect to the repo.server.

Resources