#StackBounty: #ssh #12.04 ssh intermittent blocking connections

Bounty: 50

I’m having intermittent problems with ssh in an "old" server running Ubuntu 12.04. I am getting this error message ssh_exchange_identification: Connection closed by remote host in most attempts. But from time to time I can connect by using ssh -vvv.

This server (ventus) is part of a cluster whose nodes (ventus2-5) were configured with ssh-keygen to ssh without asking for a password, it was running fine until this week. Now I can ssh from the main node (ventus) to any of ventus2-5 but it is not possible to ssh from the other nodes to ventus.

This is the output of ssh -v from node 5 (ventus5) to the main node (ventus)

meteo@ventus5:~$ ssh -v ventus
OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ventus [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/meteo/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/meteo/.ssh/id_rsa-cert type -1
debug1: identity file /home/meteo/.ssh/id_dsa type -1
debug1: identity file /home/meteo/.ssh/id_dsa-cert type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host

trying ssh -vvv I get the same error most times but from time to time is it possible to connect, both from cluster nodes or external IP (PINAR host trying to connect to ventus)

meteo@PINAR:~$ ssh -vvv ventus
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolving "ventus" port 22
debug2: ssh_connect_direct
debug1: Connecting to ventus [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file /home/meteo/.ssh/id_rsa type -1
debug1: identity file /home/meteo/.ssh/id_rsa-cert type -1
debug1: identity file /home/meteo/.ssh/id_dsa type -1
debug1: identity file /home/meteo/.ssh/id_dsa-cert type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/meteo/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/meteo/.ssh/id_ed25519 type -1
debug1: identity file /home/meteo/.ssh/id_ed25519-cert type -1
debug1: identity file /home/meteo/.ssh/id_ed25519_sk type -1
debug1: identity file /home/meteo/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/meteo/.ssh/id_xmss type -1
debug1: identity file /home/meteo/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
kex_exchange_identification: Connection closed by remote host

from iptables -nL I found this

Chain sshguard (1 references)

DROP       all  --  192.168.1.1          0.0.0.0/0  

Have tried different options for iptables and removed this last line but the problem persists.

Any idea will be very welcome, thanks in advance


Get this bounty!!!

#StackBounty: #bash #ssh #zsh #source Source a file after ssh login drops to prompt

Bounty: 50

One-liner question: How do I automatically source a remote file on remote host after logging in via SSH via a bastion host?

I need to source a file containing a list of aliases + shell user defined functions on a remote host after ssh-ing into it.

The file exists on remote maching in /tmp folder e.g. /tmp/my-rc

Searching other posts and internet I have found

ssh -t user@domain.com 'source /tmp/my-rc; bash -l'

The problem is that I do get a terminal, but none of the aliases are set since it’s a new bash shell’

Thinking, that the source should be done after the shell is attached, tried the below but this also doesn’t work. There is no error, I get the terminal but don’t think the file got sourced (verified by echoing dummy message from /tmp/my-rc file)

ssh -t user@domain.com 'bash -l; source /tmp/my-rc'

Even tried with ‘.’ instead of source, no luck.

Any help.

Note1: Bash or ZSH any shell solution would do.

Note2: The actuall ssh is via a proxy command i.e. a hop over bastion host (Just mentioning if it is relevant at all)

Note3: I don’t have privilage of a profile rc or bashrc or even a home directory on the remote host.


Get this bounty!!!

#StackBounty: #macos #ssh #openssh Set PATH when SSH into MacOS

Bounty: 50

My problem is

$ ssh localhost fswatch          
bash: fswatch: command not found

when without SSH command (i.e. fswatch) works fine.

I found that PATH in SSH session is default Mac’s

$ ssh localhost echo $PATH        
/usr/bin:/bin:/usr/sbin:/sbin

since without SSH

$ echo $PATH
/Users/kyb/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I really do not remember how have I set up the PATH, but sure ~/.bashrc and ~/.bash_profile do not edit PATH variable. There is a config file /etc/paths:

$ cat /etc/paths         
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Homebrew, npm, pip usually install programs to /usr/local/bin, so all installed programs are there and I can’t access them via ssh localhost command on my MacOS. There is no problem with Linux.

So my question is how to configure OpenSSH to use PATHs from /etc/paths and /etc/paths.d?

I also tried to hack:

$ ssh localhost sh -lc 'echo empty;echo $PATH'

/usr/bin:/bin:/usr/sbin:/sbin
$ ssh localhost bash -lc 'echo empty;echo $PATH'

/usr/bin:/bin:/usr/sbin:/sbin

first line is always empty, don’t you know why?

And my final workaround

$ ssh localhost bash -lc ':; 
    export PATH="$( cat /etc/paths /etc/paths.d/* | tr \\n : )"; 
    echo $PATH; 
    fswatch --version'
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/VMware Fusion.app/Contents/Public
fswatch 1.14.0
Copyright (C) 2013-2018 Enrico M. Crisostomo <enrico.m.crisostomo@gmail.com>.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Enrico M. Crisostomo.

Here first :; is important because first command is somehow dropped from execution

System: MacOS Mojave 10.14.5
ssh -V: OpenSSH_7.9p1, LibreSSL 2.7.3
bash --version GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)


Get this bounty!!!

#StackBounty: #command-line #networking #ssh Meaning of SSH command with 2 IPs

Bounty: 50

Often I have seen ssh commands like:

ssh user1@user2@<one-ip-address>@<second-ip-address

First I thought this is to ssh through another server. But several questions and examples like How do I SSH to machine A via B in one command? gives better solutions for server through ssh.

So, my question is what kind of scenarios we have to use the above kind of ssh commands. What is the destination of the ssh command?


Get this bounty!!!

#StackBounty: #ubuntu #command-line #ssh #x2go Git auth on EC2 works via command line within X2GO, but not by SSH

Bounty: 50

I work on multiple EC2 instances which each contain repos that need frequent updating. So I ssh to the EC2 instance, cd to the repo, and run git pull. Simple enough.

The problem is outlined in the diagram below. The git pull only works when I

  • from my laptop, log remotely into my workstation via X2G0
  • open a terminal window in the GUI
  • ssh into the EC2 from within the workstation

It does not work when I:

  • ssh directly to the EC2 from my laptop, even though I authenticate with the same key

It even does not work when I

  • from my laptop, ssh into my workstation
  • ssh into the EC2 from within the workstation

It is the last one that is a particular puzzler and has cost me some productive time when X2GO is not feasible. What settings could be different about opening a terminal window within the Ubuntu GUI, and then using ssh there, that are not present when I ssh to the same computer and am therefore on the command line already? All the same environment variables are present.
Diagram


Get this bounty!!!

#StackBounty: #linux #networking #ssh #port-forwarding #port Can access port on public IP but not private

Bounty: 100

I have a PC running a web server on port 8080, and SSHd running on port 22. In my router settings, I have forwarded port 8080 to 80, and set up an ANAME record on my domain pointing to the public IP. I am able to access my site on both my public IP port 80 and on my domain. However, I am not able to access the port using the private IP, or SSH into the PC. The PC has a static IP configured. How can I fix this?


Get this bounty!!!

#StackBounty: #macos #ssh #macos-mojave #syslog How to get SSH logs and send to remote syslog server in macOS?

Bounty: 50

On Linux, I can get sshd logs such as:

sshd Accepted publickey for user from xxx.xxx.xxx.xxx port xxx ssh2: RSA SHA256:.....

and send them to a remote syslog server by adding a file in /etc/rsyslog.d/

How can I get similar data on MacOS 10.14 (Mojave), and also have macOS send the data to a remote syslog server?

I can get the data I want using this command:

log stream --process sshd --info --predicate "messageType = 'info'"

Now need to figure out how to configure ASL (Apple System Logger).


Get this bounty!!!

#StackBounty: #ssh #ftp #mac-osx #unix #sftp How to set seprate current directory for sftp in macos?

Bounty: 50

On my macos i am able to login to sftp as sftp localhost. When i run !pwd it shows me default directory is /Users/username but i want to change it /Users/username/Sites/wordpress.

I edited /etc/ssh/sshd_config file & added below lines at bottom of file

Match User username
       X11Forwarding no
       AllowTcpForwarding yes
       PermitTTY yes
       PasswordAuthentication yes
       ChrootDirectory /Users/username/Sites/wordpress

But when i again try to login with sftp localhost after password prompt it gives me error as below

client_loop: send disconnect: Broken pipe
Connection closed 

Please tell me how can fix this error ?


Get this bounty!!!