could not settle on kex algorithm - SFTP connection failed - ruby

Tried to connect SFTP server using RSA private key with a ruby script. It's not connecting. But it's working using Filezilla.
Code example:
require 'net/sftp'
sftp = Net::SFTP.start('hostname', 'user', password: '', port: 'port', keys: '~/.ssh/private_key.pub')
sftp.connect
Output:
Failed to connect to hostname: could not settle on kex algorithm
Server kex preferences: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
Client kex preferences: ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
Using sftp command with -oKexAlgorithms argument it's working on the terminal.
sftp -i ~/.ssh/private_key.pub -P 16321 -oKexAlgorithms=diffie-hellman-group1-sha1 -c aes128-cbc user#host

Related

How to change the ssh port connection on Windows?

I am trying to connect to GitLab with an ssh key from a Windows laptop. The problem is the port of the repository has changed, and I cannot manage to change the default port 22 on the config.
I have tried with a mac laptop and it worked by editing the config file, but I cannot do the same on Windows. I created a config file with touch config and added this
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 1122
But it does not work, terminal says it is still connecting to port 22:
C:\Users\parko>ssh -T git#gitlab.com
kex_exchange_identification: read: Connection reset
C:\Users\parko>ssh -T git#gitlab.%myRepository%.com
ssh: connect to host gitlab.%myRepository%.com port 22: Connection timed out
I also tried a solution that I found in an article to change the port directly on the command when trying to connect, but it also did not work:
C:\Users\parko>ssh -T git#gitlab.%myRepository%.com:1123
ssh: Could not resolve hostname gitlab.%myRepository%.com:1123: No such host is known.
Any idea what can be happening?
Thanks in advance.
Like #ewong said, I had to add the port with the -p parameter instead of at the end of the command
ssh -p [port number] -T git#[gitlab URL]
for me it was:
C:\Users\parko>ssh -p 1123 -T git#gitlab.%myRepository%.com

Vscode SSH Jump Failed with macOS

I can connect to the first server with key but cannot connet to the second server jumping with the first server. I doubt it is a bug on MacOS because I can jump to the seceond server with command line. Is there ANYONE knows what happened here?
Here is the config:
Host comp
HostName xx.xx.xxx.xxx
User xxxx
Port 22
IdentityFile ***************
Host local
HostName 127.0.0.1
Port ****
User xxxx
ProxyCommand ssh -q -x -W %h:%p comp
IdentityFile ***************
Here is the error information:
[19:55:48.660] Log Level: 2
[19:55:48.662] remote-ssh#0.55.0
[19:55:48.662] darwin x64
[19:55:48.663] SSH Resolver called for "ssh-remote+localhost", attempt 1
[19:55:48.663] SSH Resolver called for host: localhost
[19:55:48.663] Setting up SSH remote "localhost"
[19:55:48.669] Acquiring local install lock: /var/folders/5q/****************_tr0000gn/T/vscode-remote-ssh-localhost-install.lock
[19:55:48.713] Looking for existing server data file at /Users/gy/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-localhost-************************************-0.55.0/data.json
[19:55:48.742] Using commit id "***********************************" and quality "stable" for server
[19:55:48.743] Install and start server if needed
[19:55:48.779] Checking ssh with "ssh -V"
[19:55:48.854] > OpenSSH_8.1p1, LibreSSL 2.7.3
[19:55:48.860] Using SSH config file "/Users/gy/.ssh/config/vscodeconfig"
[19:55:48.861] askpass server listening on /var/folders/5q/******************_tr0000gn/T/vscode-ssh-askpass-**********************************.sock
[19:55:48.862] Spawning local server with {"ipcHandlePath":"/var/folders/5q/**************_tr0000gn/T/vscode-ssh-askpass-********************************.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","54815","-o","ConnectTimeout=15","-F","/Users/gy/.ssh/config/vscodeconfig","localhost"],"dataFilePath":"/Users/gy/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-localhost-*********************************-0.55.0/data.json"}
[19:55:48.862] Local server env: {"DISPLAY":"1","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer)","VSCODE_SSH_ASKPASS_MAIN":"/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/var/folders/5q/********************_tr0000gn/T/vscode-ssh-askpass-**********************************.sock"}
[19:55:48.871] Spawned 34492
[19:55:48.987] > local-server> Spawned ssh: 34493
[19:55:49.008] stderr> OpenSSH_8.1p1, LibreSSL 2.7.3
[19:55:50.129] stderr> kex_exchange_identification: Connection closed by remote host
[19:55:50.131] > local-server> ssh child died, shutting down
[19:55:50.136] Local server exit: 0
[19:55:50.136] Received install output: OpenSSH_8.1p1, LibreSSL 2.7.3
kex_exchange_identification: Connection closed by remote host
[19:55:50.137] Stopped parsing output early. Remaining text: OpenSSH_8.1p1, LibreSSL 2.7.3kex_exchange_identification: Connection closed by remote host
[19:55:50.137] Failed to parse remote port from server output
[19:55:50.141] Resolver error: Error:
at Function.Create (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:1:130564)
at Object.t.handleInstallOutput (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:1:127671)
at Object.t.tryInstallWithLocalServer (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:102339)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async /Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:104310
at async Object.t.withShowDetailsEvent (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:109845)
at async /Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:100912
at async R (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:97702)
at async Object.t.resolveWithLocalServer (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:100561)
at async Object.t.resolve (/Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:107840)
at async /Users/gy/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/extension.js:127:141955
[19:55:50.143] ------
Could someone enlighten me on the reason for the problem or on a possible solution ? Thanks !
I have the similar problem.
Later it disappears after I turn off the agent server.
Maybe you can try this.

SSH in git behind proxy on windows - FATAL: Connection closed by peer

By a SSH connection, I'm trying to clone a Repository from a Company BitBucket which use 7999 port (not Bitbucket.org) using Git Bash. I've generated the RSA key and added the public key into my profile of the BitBucket Company and the keys re located in ~/.ssh, I've setup the proxy by using git config --global http.proxy http://userPrx:pwdPrx#ipProx:8080 (because I'm under the Company Proxy) and also I have setup my config file as this post suggest. Then, when I try to Test the connection I get this:
$ ssh -vT globaldevtools -p 7999
OpenSSH_7.3p1, OpenSSL 1.0.2j 26 Sep 2016
debug1: Reading configuration data /c/Users/MyUser/.ssh/config
debug1: /c/Users/MyUser/.ssh/config line 5: Applying options for globaldevtools
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Executing proxy command: exec /C/Users/MyUser/AppData/Local/Programs/Git/mingw64/bin/connect.exe -S IpProxy:8080 x.x.x.x 7999
debug1: permanently_drop_suid: 1104711
debug1: identity file /c/Users/MyUser/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/MyUser/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
FATAL: Connection closed by peer.
ssh_exchange_identification: Connection closed by remote host
This is my config file:
ProxyCommand /C/Users/MyUser/AppData/Local/Programs/Git/mingw64/bin/connect.exe -S IpProxy:8080 %h %p
Host globaldevtools
User git
Port 7999
Hostname x.x.x.x
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
I must indicate that in this file (config) instead of IpProxy:8080 I've tried with
http://IpProxy:8080
http://usrProx:pwdProx#IpProxy:8080
usrProx:pwdProx#IpProxy:8080
Do I have to do something else? Did I miss something? All help is appreciated.

SSH config on Windows when working under a HTTP proxy

I'm trying to set up my ~/.ssh/config file to connect on servers through the HTTP proxy my company is using, but it's falling everytime...
Does anyone know how to do this ?
I'm working on Windows 7, using the Git Bash tool, and here is my current ~/.ssh/config:
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
ProxyCommand connect -H XX.XX.XX.XXXX:8080 %h 443
The command ssh -T git#github.com -v outputs :
OpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /c/Users/name/.ssh/config
debug1: /c/Users/name/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec connect -H XX.XX.XX.XXXX:8080 github.com 443
debug1: permanently_drop_suid: 1201653
debug1: identity file /c/Users/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/gregv/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
ssh_exchange_identification: Connection closed by remote host
OK, my problem was actually the port set on 443, here is the correct ~/.ssh/config file file that is working for me :
Host github.com
IdentityFile ~\.ssh\id_rsa
ProxyCommand connect -H XX.XX.XX.XXXX:8080 %h %p
ForwardAgent yes

Connecting to Bitbucket using ssh through proxy

I have run out of options. I have tried several methods but none have worked so I hope someone can help me.
At work we operate behind a proxy; at the moment I am setting a repository that I would like to pull from and push from. I want to this using ssh so I don't need the password at work or when I take the laptop at home.
The repository is created.
I have created an additional distinct ssh key and added it in bitbucket setting profile.
I have loaded the ssh key using the following command - ssh-add ~/.ssh/personal
I have checked and the key is loaded.
when I try to connect to my repository,using clone or any other action(push or pull),it doesn't work
operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have also tried to create a config file in .ssh/ with the following values
Host personalid
HostName bitbucket.org
IdentityFile ~/.ssh/personal
but still it doesn't work
I don't know whether is a proxy issue or something else, I thought ssh should allow me to bypass everything.
Can someone give me an idea on how to diagnose the problem?
Thank you
=========
UPDATE: result of the command ssh -Tv hg#bitbucket.org
ssh -Tv hg#bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to bitbucket.org [131.103.20.167] port 22.
debug1: connect to address 131.103.20.167 port 22: Operation timed out
debug1: Connecting to bitbucket.org [131.103.20.168] port 22.
debug1: connect to address 131.103.20.168 port 22: Operation timed out
ssh: connect to host bitbucket.org port 22: Operation timed out
=========
If i use port 443
ssh -Tv -p 443 hg#bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to bitbucket.org [131.103.20.167] port 443.
debug1: connect to address 131.103.20.167 port 443: Operation timed out
debug1: Connecting to bitbucket.org [131.103.20.168] port 443.
debug1: connect to address 131.103.20.168 port 443: Operation timed out
ssh: connect to host bitbucket.org port 443: Operation timed out
when trying ssh -Tvp443 hg#altssh.bitbucket.or
ssh -Tvp443 hg#altssh.bitbucket.org
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/username/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to altssh.bitbucket.org [131.103.20.174] port 443.
debug1: connect to address 131.103.20.174 port 443: Operation timed out
ssh: connect to host altssh.bitbucket.org port 443: Operation timed out
The best diagnosis would be to fake an SSH session:
ssh -Tv hg#bitbucket.org
(It doesn't matter whether you're using Git or Mercurial; this test does the same thing either way.)
There'll be a wall of output from the command, thanks to the -v, but the first thing to look for would be a line like this at the end with your specific username:
logged in as cpu2007.
That will establish that a) you're reaching Bitbucket and b) your key is added to your account. If you don't see a line like that, then that should help you diagnose your problem.

Resources