Private Git server is invisible or unreachable - windows

On Ubuntu machine I created a repo' as follows
netcomo#netcomoserver:/opt/git/groupware.git$ ll
Total 12
drwxr-xr-x 3 git git 4096 April 26 16:18 ./
drwxr-xr-x 3 git git 4096 April 26 13:50 ../
drwxr-xr-x 7 git git 4096 April 26 16:18 .git/
netcomo#netcomoserver:/opt/git/groupware.git$
On Windows 7 where I want to clone the repo' I'm having below error.
What could be the reason? (as you can see the repo' server is reachable)

Looks like your git server is reachable.
You are using SSH to access the GIT repo. In that case you need to create an SSH key.
If you doing so, store your public key
.ssh/authorized_keys
on your Ubuntu maschine.
On Windows you can create SSH keys using Putty http://www.putty.org/

I should have checked a few things as follows:
To copy public key from a client machine to the server using "ssh-copy-id" command (example is shown below), I need to change a option of sshd_config file to 'yes' on the server computer.
Command:
$ ssh-copy-id ~/.ssh/id_rsa netcomo#netcomoserver
$ sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes
After copying the public key to the server, the 'yes' changed above needs to be changed back to 'no'
For your reference, if you need to access multiple server accounts, you have to copy the same public key for each different accounts, see examples that follow.
$ ssh-copy-id ~/.ssh/id_rsa netcomo#netcomoserver
$ ssh-copy-id ~/.ssh/id_rsa netcomo2#netcomoserver
.

Related

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.

How can I add an already generated SSH key to git bash?

I have an SSH key saved in D:/keys folder. I want to add it to my git bash. All the tutorials I found is how to generate SSH key using gitbash and load it to github/gitlab. I generated my SSH key using puttygen. Now I want to add it to my git bash so that I can clone a repository from remote. How can I do that?
On windows you might need to start the ssh agent like this
# start the ssh-agent in the background
$ eval $(ssh-agent -s)
> Agent pid 59566
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
$ ssh-add <path/to/key>
Got this information from here under "Adding your SSH key to the ssh-agent":
https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
I don't think there is any specific config in gitbash itself. You have to put the key in the default location ~\.ssh/id_rsa and it will be used. If you need to have it somewhere else you could do so with a config file same as on Linux ~/.ssh/config
host example.com
HostName example.com
IdentityFile ~/.ssh/id_rsa
User git
Don't forget to set the permissions chmod 400 ~/.ssh/id_rsa
Assume the private key file you want to import to git bash is D:/keys folder/myprivatekey and your Git was installed in D:/Git (in which folder you would see the binary file git-bash.exe), open the file D:/Git/etc/ssh/ssh_config.
Here are some texts in this file:
...
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
...
Simply add a new line and save it:
...
# StrictHostKeyChecking ask
IdentityFile "D:/keys folder/myprivatekey"
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
...
And the key is already added.
I was able to get it so the passphrase is only prompted for on the first window that's opened after booting using the script at Auto-launching ssh-agent on Git for Windows. I did find, however, it didn't work when I added it add it to either ~/.profile or ~/.bashrc. I needed to add it to ~/.bash_profile for it to get picked up and used by Git Bash on Windows.

git ssh fails to access host but succeed when direct IP is used (Windows 10)

I am using git/bash in Windows 10 and try to clone a repository.
When I use the command: git clone username#hostname, I get:
ssh: Could not resolve hostname stbcmgit: Name or service not known
However, when I use a direct IP address instead of the hostname (git clone username#x.x.x.x), the access is successful and the clone starts.
Notes:
"known_hosts" file is located at c:\Users\myname\.ssh
The file is taken from my Linux account where everything works fine there.
The .ssh folder contains also the id_rsa and id_rsa.pub keys (copied also from Linux).
When I use 'ls $HOME/.ssh', I see these files listed.
Using Windows 10.
Thanks.
You should check /etc/hosts and add such a line if it doesn't exist:
x.x.x.x hostname
If the host's IP doesn't change, you can simplify the whole command by creating $HOME/.ssh/config like this
Host YourHost
HostName x.x.x.x
User username
IdentityFile ~/.ssh/id_rsa
PubKeyAuthentication yes
Now you can run these commands:
git clone YourHost:repo
ssh YourHost
In Windows 10 and after the latest updates concerning the "Windows Subsystem for linux" aka "Bash" now you MUST assign any desired hostname with its relative IP Address by editing this file:
C:\Windows\System32\drivers\etc\hosts
P.S: on your linux please check /etc/hosts and not the 'known_hosts' file
~/.ssh/config may contain such definitions.
These definitions contain port numbers also (I think /etc/hosts can't).

Icinga2 check_by_ssh plugin returns 255 without running the command

I'm configuring a Icinga2 server and want it to run local scripts on external machines using the check_by_ssh plugin, and I encountered a strange issue. I've searched for an answer for few hours, but no luck.
My command object looks as follows:
object CheckCommand "check_procs" {
import "by_ssh"
vars.by_ssh_logname = "root"
vars.by_ssh_port = "22"
vars.by_ssh_command = "/tmp/test.sh"
vars.by_ssh_identity = "/etc/icinga2/conf.d/services/id_rsa.pub"
vars.by_ssh_ipv4 = "true"
vars.by_ssh_quiet = "true"
}
The content of test.sh is simply exit 0. I have a trust between my Icinga box and the remote machine I'm running the command at.
When I'm executing the command thru shell, it works
[root#icinga ~]# ssh root#10.10.10.1 -C "/tmp/test.sh"
[root#icinga ~]# echo $?
0
But when it is executed by the server, I see on my Icingaweb2 this output:
UNKNOWN - check_by_ssh: Remote command '/tmp/test.sh' returned status 255
Now I have added a touch success to test.sh script, in order to see if it is executed at all - but it seems it doesn't. That means when Icinga executes my script, it fails before even executing it.
Any clues what can it be? There are no many examples online either of check_by_ssh with Icinga2.
NOTE: Icinga uses root user to identify with the remote server. I know this is not best practice, but this is development env.
UPDATE: I think I have found the issue. The problem is that I'm trying to use root user to login the remote machine. This IS NOT supported, even with public key authentication. The script has to be executed with the user icinga
2nd Update: I got it works. The issue was keys authentication, the fact that icinga uses the user icinga to execute the command (even when using by_ssh_logname attribute) and the addition of vars.by_ssh_options = "StrictHostKeyChecking no"
My problem was that the used rsa key files wasn't owned by the "nagios" user:
-rw------- 1 nagios nagios 3.2K Nov 30 14:43 id_rsa
-rw-r--r-- 1 nagios nagios 766 Nov 30 14:42 id_rsa.pub
I've found the issues, there were few of them in my case.
Icinga used icinga user to login through SSH, even when I used -l root. So, to install ssh keys I had to execute ssh-copy-id icinga#HOST under root user (Icinga shell is set to /sbin/nologin)
I then copied the private key (again, of the root user) to icinga folder so it is accessible for the application, and changed the ownership of the file
Next, I tried to login using icinga user to the remote machine sudo -u icinga ssh icinga#HOST -i id_rsa
If step 3 fails, you need to figure it before you continue. Next thing I did was adding StrictHostKeyChecking no to the module options.
Voila, this works now.

Install gitolite v3 on the Centos 6.4. The second user is asking a password

Please help me to understand what i am doing wrong. I have server on CentOS 6.4 and I need to install gitolite v3. What am i doing? by the first i am install one using next command:
yum install git* perl-Time-HiRes
useradd -m --system --shell /bin/bash --user-group gitolite
su - gitolite
mkdir bin
echo "PATH=$HOME/bin:$PATH" > .bash_profile
source .bash_profile
ssh-keygen -t rsa
cp .ssh/id_rsa.pub ./gitolite.pub
git clone git://github.com/sitaramc/gitolite
gitolite/install -ln
gitolite setup -pk gitolite.pub
Install was successful. Than I clone gitolite-admin repositories:
git clone gitadmin:gitolite-admin
cd gitolite-admin/keydir
And generate public key for the new user(lodar.pub)
ssh-keygen -t rsa -f lodar
mv ./lodar ../../.ssh/lodar
Than i edit conf/gitolite.conf:
repo gitolite-admin
RW+ = gitolite
repo testing
RW+ = #all
repo empty
RW+ = lodar
Commit all changes:
git add keydir/lodar.pub
git commit -m 'add user lodar and new repo empty'
git push
And that is all. Push was successful too. After all manipulation i created .ssh/config
Host gitadmin
User gitolite
Hostname 192.168.0.1
Port 22
IdentityFile ~/.ssh/gitolite
Host gitlodar
User gitolite
Hostname 192.168.0.1
Port 22
IdentityFile ~/.ssh/lodar
But if i try to connect using
ssh gitlodar info
lodar#192.168.0.1's password:
i must to enter the password.
ssh gitadmin info
hello, gitolite, this is gitolite#lodar-14452 running gitolite3 v3.5.1-4-g2f48a3e on git 1.7.1
R W gitolite-amdin
R W testing
What am i doing wrong?
You did:
mv ./lodar ../../.ssh/lodar
I supposed you meant
cp ./lodar.pub ../../.ssh/
mv ./lodar ../../.ssh/
Because if you don't copy the public key in ~/.ssh, you wouldn't be able to use it in an ssh session.
But the other mistake is in your ~/.ssh/config file:
Host gitlodar
User gitolite # not loadar!
Hostname 192.168.0.1
Port 22
IdentityFile ~/.ssh/lodar
See "How do programs like gitolite work?":
The idea is to always use the same user to connect to the gitolite server (in your case, connect as 'gitolite'), and open an *non-interactive shell.
The force-command ssh line will call the gitolite script with a parameter representing the name of the user (here 'loadar'), because that named is registered with the public key in the ~gitolite/.ssh/authorized_keys.
$pwd
/home/lodar/gitolite-admin/keydir
$ssh-keygen -t rsa -f lodar
Last command generated two keys: public (lodar.pub) and private (lodar). I moved private key in the .ssh on my client computer. The public one stayed in keydir.
$mv ./lodar ../../.ssh/lodar
That is why after 'git push' user lodar added to giotlite repo. I checked it on the server by the command
$gitolite sshkeys-lint
sshkeys-lint: === checking authkeys file:
sshkeys-lint: === checking pubkeys:
sshkeys-lint: === gitolite.pub maps to user gitolite
sshkeys-lint: === lodar.pub maps to user lodar
YOU ARE RIGHT. MY MISTAKE was IN MY .ssh/config. Thanks for the HELP. it is working great now.

Resources