ssh permission denied when prefixing with ssh protocol - ssh

I try to add a ssh key to my GitLab account in order to use it through npm.
I added my key following https://docs.gitlab.com/ee/ssh/.
ssh -T git#gitlab.com
Is working fine and deliver the message Welcome to Gitlab, username.
But ssh -T ssh://git#gitlab.com is not working and give me this error message:
Permission denied (publickey).
And when I run npm install on my node project where I added my node module as a dependency inside the package.json file, it's returning the following error:
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#gitlab.com/myproject/myproject.git
npm ERR!
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
I added my dependency inside package.json as follow:
"my-project": "git#gitlab.com:myproject/myproject.git",
I'm not comfortable with ssh and key pairing, if anyone could tell me what is wrong with my configuration it will help me a lot, thanks.

It's kind of funny to be misled by the following line (talking about myself):
ssh -T ssh://git#gitlab.com
The command doesn't expect actually a protocol prefix, but a hostname prefixed or not by a user name followed by an arobase, as said the manual page:
ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user#]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
[-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user#]hostname [command]
Here, it takes actually ssh://git as a user name. That's why it won't log in since the user name which whom you connect has to be git, and not ssh://git.

What's the difference between "SSH", "ssh" & "ssh://"?
SSH is a transport layer protocol. link
ssh is an OpenSSH SSH client. OpenSSH is the connectivity tool for remote login with the SSH protocol. link
ssh:// is a Uniform Resource Locator (URL). link
ssh -T git#gitlab.com - Using an ssh client, log in to gitlab.com with username as git
ssh -T ssh://git#gitlab.com - Using an ssh client, log in to gitlab.com with username as ssh://git (Thanks Amessihel for the detailed answer)
ssh://git#gitlab.com/myproject/myproject.git - Instructs the application accessing this URL that it requires ssh client to access, and if there an ssh client installed on the operating system, opens the SSH client, log in to gitlab.com with username git and access the myproject/myproject.git repo. Chrome understand this URL, copy this URL on the chrome address bar and hit enter.
Just like any URL, for example, https://google.com. Many clients support HTTP, like wget, curl or a web browser, and for HTTP & HTTPS URL operating systems will open web browsers.

Related

How do I resolve Invalid SSH Key Entry error when starting App with GCE

I'm trying to launch my app on Google Compute Engine, and I get the following error:
Sep 26 22:46:09 debian google_guest_agent[411]: ERROR non_windows_accounts.go:199 Invalid ssh key entry - unrecognized format: ssh-rsa AAAAB...
I'm having a hard time interpreting it. I have the following startup script:
# Talk to the metadata server to get the project id
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
REPOSITORY="github_sleepywakes_thunderroost"
# Install logging monitor. The monitor will automatically pick up logs sent to
# syslog.
curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash
service google-fluentd restart &
# Install dependencies from apt
apt-get update
apt-get install -yq ca-certificates git build-essential supervisor
# Install nodejs
mkdir /opt/nodejs
curl https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.gz | tar xvzf - -C /opt/nodejs --strip-components=1
ln -s /opt/nodejs/bin/node /usr/bin/node
ln -s /opt/nodejs/bin/npm /usr/bin/npm
# Get the application source code from the Google Cloud Repository.
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/${PROJECTID}/r/${REPOSITORY} /opt/app/github_sleepywakes_thunderroost
# Install app dependencies
cd /opt/app/github_sleepywakes_thunderroost
npm install
# Create a nodeapp user. The application will run as this user.
useradd -m -d /home/nodeapp nodeapp
chown -R nodeapp:nodeapp /opt/app
# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/opt/app/github_sleepywakes_thunderroost
command=npm start
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF
supervisorctl reread
supervisorctl update
# Application should now be running under supervisor
My instance shows I have 2 public SSH keys. The second begins like this one in the error, but after about 12 characters it is different.
Any idea why this might be occurring?
Thanks in advance.
Once you deployed your VM instance, its a default setting that the SSH key isn't
configure yet, but you can also configure the SSH key upon deploying the VM instance.
To elaborate the answer of #JohnHanley, I tried to test in my environment.
Created a VM instance, verified the SSH configuration. As a default configuration there's no SSH key configured as I said earlier you can configure SSH key upon deploying the VM
Created a SSH key pair via CLI, you can use this link for instruction details
Navigate your VM instance, Turn off > EDIT > Security > Add Item > SSH key 1 - copy+paste generated SSH key pair > Save > Power ON VM instance
Then test the VM instance if accessible.
Documentation link How to Add SSH keys to project metadata.

Generating SSH key in git bash, i can't get git agent

When I am trying to generate SSH key in git bash, I can't get git agent when we run this command
eval $(ssh-agent -s)
then I will get this error
unix_listener: cannot listen on path /tmp/ssh-xoEnzGUu8XxU/agent.1287: Permission denied
How can I resolve this?
As seen here, that could be a permission issue for writing the SSH socket.
Check the permission associated to /tmp or /tmp/ssh-xoEnzGUu8XxU/agent.1287
Or try:
eval $(ssh-agent -a ~/.ssh-agent.$$)
The socket will be written in your $HOME instead of /tmp: no more permission issue.

ssh_exchange_identification issue raising when trying to install Homebrew in my macOS Sierra 10.12.6

I have searched many answers. But, none of them solved my issues.
I have tried to install homebrew via terminal, by using /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Following error received:
Attempt 1:
Donal-Mac-mini:~ mymac$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
ssh_exchange_identification: read: Operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
Donal-Mac-mini:~ mymac$
Attempt 2:
Donal-Mac-mini:~ mymac$ git clone https://github.com/Homebrew/homebrew.git
Cloning into 'homebrew'...
ssh_exchange_identification: read: Operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Donal-Mac-mini:~ mymac$
Issue fixed with the help of these link.
By Adding, SSH keys to my GitHub account and tried to install Homebrew.
Successfully installed.
Following steps:
Generate Key to your GitHub Account:
ssh-keygen -t rsa -b 4096 -C "yourusername#github.com"
Password:
It will ask minimum 5 chars password
To Check PORT:
eval "$(ssh-agent -s)"
Add Generated Key to Git:
ssh-add -K ~/.ssh/id_rsa
Copy that Key:
pbcopy < ~/.ssh/id_rsa.pub
PASTE IN SSH KEYS under SETTINGS in YOUR GITHUB ACC:
Next in Terminal,
ssh -T git#github.com
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
Start to Install Homebrew.

Setup ICP 2.1.0 (IBM Cloud Private) fails due to ssh troubles. Single host installation under Ubuntu

When running
sudo docker run --net=host -t -e LICENSE=accept -v $(pwd):/installer/cluster ibmcom/icp-inception:2.1.0-ee install
I get fatal: [192.168.201.130] => Failed to connect to the host via ssh: Permission denied (publickey,password).
I have debugged the session:
root#icpecm:/opt/ibm-cloud-private-2.1.0/cluster# ssh -vvv -i cluster/ssh_key root#192.168.201.130
this is successful.
Have you copied the public key in all the nodes?
In your case:
$ ssh-copy-id -i .ssh/id_rsa root#192.168.201.130

Centos 6.5, WHM : Rsync with Root disabled using ssh user from the Wheel Group

I'm trying to rsync files with my server, which has root login via ssh disabled. I'm trying to use one of the users I've created and added to to the wheel group. Usually - when I log in via ssh I run
su - root
then type the password and can run everything as root user, but not quite sure how to do it with rsync as I need to upload the files outside of the user directory.
When I run:
rsync -avz files/* sshwheeluser#ip_address:/home/newproject/public_html/
I get:
rsync: ERROR: cannot stat destination "/home/newproject/public_html/": Permission denied (13)
I have added the following to the /etc/sudoers file:
rsyncuser ALL= NOPASSWD:/usr/bin/rsync
plus I've un-commented:
%wheel ALL=(ALL) NOPASSWD: ALL
I've also tried to run the command with –rsync-path="sudo rsync" as suggested in some posts, but still no luck:
rsync -avz –rsync-path="sudo rsync" files/* sshwheeluser#ip_address:/home/newproject/public_html/
Next I tried to use it with additional -e "ssh":
rsync -avz -e "ssh" –rsync-path="sudo rsync" files/* sshwheeluser#ip_address:/home/newproject/public_html/
which changed the error message (looks like we're getting somewhere):
stdin: is not a tty
sudo: sorry, you must have a tty to run sudo
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-40/rsync/io.c(452) [sender=2.6.9]
This post suggests that require_tty and tty_tickets should be disabled in sudoers, but I can't find these options in the /etc/sudoers file.
I've added (as recommended) Defaults !tty_tickets to the sudoers, but still the same message.
Any idea what else I need to do to make it work?
You should check Selinux logs, rsync is probably been blocked by Selinux.
You can also try to run:
semanage permissive -a rsync_t