Why ssh keep asking passphrase while cloning project from github? - terminal

So I setup ssh key on my Ubuntu terminal(WSL2) using fish shell.
I installed fish_ssh_agent, and it worked I am not entering passphrase every time I push some changes in my remote project, I am doing it only once. so ssh-agent is enabled, but when I am trying to clone any project on my PC, ssh is asking me passphrase every time.
Is this normal or need additional setup, to enter it once and after clone projects without passphrase,like I am doing with git push ?

I solved my problem by entering this commands in config files in Ubuntu terminal,where I am using fish shell and in Git Bash too:
For fish:
nano ~/.config/fish/config.fish
eval (ssh-agent -c) && ssh-add ~/.ssh/id_ed25519
for Git bash:
nano ~/.bash_profile
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519

Related

Why can't I `source` ssh-agent and ssh-add with in bash script?

When I tried git push, I get the following error.
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I know that I should specify my own key here, so I type the following in bash window, and it works fine.
ssh-agent bash
ssh-add ~/.ssh/id_rsa_lrz
git push
However, I'd like make things easy, so I have a set_env.sh like this
ssh-agent bash
ssh-add ~/.ssh/id_rsa_lrz
And I type in my bash window like this
. set_env.sh
git push
However, I get the ERROR: Repository not found. error again, but why?
This is because when you run :
. set_env.sh
You will be inside the bash session setup by ssh-agent bash where ssh-add ~/.ssh/id_rsa_lrz has not run yet.
What you need is putting in set_env.sh
eval "$(/usr/bin/ssh-agent)"
ssh-add ~/.ssh/id_rsa_lrz

It' s possible to works SSH and git command in gitlab-ci?

In my gitlab-ci.yml, I have an SSH connection to another server, all my command are working except the git commands
They block the script with the message:
WARNING: terminal is not fully functional
- (press RETURN)
and my script is blocked
My code in gitlab-ci :
allow_failure: false
script:
- ssh -tt root#1IP 'cd PATH; git branch;docker run -it -v $PWD:PATH -w /PATH cypress/included:6.5.0 | tee result.txt'
Without the git command, it's work.
Of course, in my remote server, git branch work's fine.
Any ideas ?
Thanks :) :)
That is an error message coming from less, used as a pager by Git, as I documented here.
Try:
git config --global core.pager "less -d"; git branch; ... (rest of the commands)
The -d option (from less man page) option suppresses the error message normally displayed if the terminal is dumb;

Using cygwin ssh-agent is running but git is still prompting for passphrase

I'm using cygwin as my terminal on Windows 7. I have found several suggestions to run ssh-agent in cygwin so I don't have to enter my password every time I run a git fetch/pull/push. I added the following to my .bash_profile and restarted my cygwin session:
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent -s | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
It looks as if the ssh-agent and ssh-add are run successfully, but I am still prompted for my password.
Initialising new SSH agent...
succeeded
Enter passphrase for /cygdrive/c/Users/<username>/.ssh/id_rsa:
Identity added: /cygdrive/c/Users/<username>/.ssh/id_rsa (/cygdrive/c/Users/<username>/.ssh/id_rsa)
$ ssh-add -l
2048 <fingerprint> /cygdrive/c/Users/<username>/.ssh/id_rsa (RSA)
$ git fetch --all
Fetching origin
Enter passphrase for key '/c/Users/<username>/.ssh/id_rsa':
I am in fact using SSH and not HTTPS for my git connection (redacted private info):
$ git remote -v
origin ssh://git#XXX/XXX.git (fetch)
origin ssh://git#XXX/XXX.git (push)
The closest problem I've found for this issue is the following question:
ssh-agent doesn't work / save me from typing passphrase for git
However, I didn't rename my ssh under /git/bin.
Any suggestions on how to diagnose this issue? Thanks!
Here is an easier solution to this than the one above:
Launch Services (can be found by typing Services in the search
box on the Taskbar)
Edit the settings of the "OpenSSH Authentication Agent"
Set the Startup type to Automatic and Start the Service
Launch the Edit the System Environment Variables (type Environment
in the search box on the Taskbar)
Add GIT_SSH variable with the value set to
"C:\Windows\System32\OpenSSH\ssh.exe"
Now when an SSH key is added, you will not need to continue to type the passphrase in a Windows command prompt or in a Cygwin Bash shell.
The problem is still remain. Seems it is related to the different paths and hasn't been fixed yet.
You may consider to use expect as an alternatif to ssh-agent for login with passphrase interaction.
In Linux it use to be installed like this:
$ sudo apt-get update
$ apt-get install --assume-yes --no-install-recommends apt-utils expect
In cygwin you may find it under Tcl:
Here is a simple step on how to use it.
Create a file, lets locate it and name ~/.expect_push
#!/usr/bin/expect -f
spawn git push origin master
expect "Username for 'https://github.com':"
send "<username>\n";
expect "Password for 'https://<username>#github.com':"
send "<password>\n";
interact
Change the above <username> and <password> to your login id with following notes:
Modify the contents follow precisely to your git login interaction.
If your <password> contain the char $ put it as \$ otherwise the authentication will be failed.
For example if your password mypa$$word then put <password> as mypa\$\$word.
Create another file ~/.git_push
#!/usr/bin/bash
git remote set-url origin git#github.com:<username>/<repo>.git
git add .
git commit -m "my test commit using expect"
expect ~/.ssh/.expect_push
Make them executable and create symlink in /bin
$ chmod +x ~/.expect_push
$ chmod +x ~/.git_push
$ cd /bin
$ ln -s ~/.git_push push
Then you can push to the remote without need to fill in username and password or passphrase
$ cd /path/to/your/git/folder
$ push

Perlbrew installation through vagrant provision.sh

I want to automate the installation of perlbrew into the vagrant box. I use .sh file to accomplish this.
provision.sh
apt-get update
sudo -H -u vagrant bash -c " \curl -kL https://install.perlbrew.pl | bash"
sudo -u vagrant bash -c "source ~/perl5/perlbrew/etc/bashrc"
After ssh into the vagrant i expect that
$ which perlbrew
will return
/home/vagrant/perl5/perlbrew/bin/perlbrew
but unfortunately it returns nothing.
There is no way the settings applied by your source ~/perl5/perlbrew/etc/bashrc command would be visible in another bash session (and a SSH session executes a new bash process).
You need to add the command source ~/perl5/perlbrew/etc/bashrc to one of the bash "rc" files.
For a single user with the following command:
echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.bashrc
For all users with the following command:
echo "source ~/perl5/perlbrew/etc/bashrc" >> /etc/bash.bashrc
This way every time a new bash session is started, it will run source ~/perl5/perlbrew/etc/bashrc and apply the settings.

I changed /etc/passwd to git-shell and changed it back, but now shell not working

I was following the instruction on how to set up a git server here, and I removed the ssh access from the git user by setting /etc/passwd file to /usr/bin/git-shell.
Later I found out that I still want to ssh as git, so I reset it back to /bin/sh. I could ssh back, but the shell prompt looked all strange today. Previously, the prompt was
git#xyz.com $
but now it's just
$
Tab Autocomplete is gone. History is also gone. I am not sure what files got removed when I switched to git-shell. How do I recover from this?
chsh git -s /bin/bash should fix it (I prefer to use the chsh program instead of editing /etc/passwd by hand to change an account's login shell)
Maybe it was not /bin/sh before, try setting it as
/bin/bash

Resources