SSH multiplexing hangs - ssh

can someone explain to me how exactly this works.
I have this config in ~/.ssh/config
host *
ControlMaster auto
ControlPersist yes
ControlPath ~/.ssh/muxmasters/%C
First time I ssh, takes some time to connect, after that if I exit and ssh again it is faster, and that's what I need.
The problem happens when I exist the ssh connection, and after 5 minutes, if I try to ssh again it hangs like minutes and then I get the ssh connection, when exiting I checked the socket file and it is there, so I dont actually understand how this works.
Not sure if there is a way to keep that speed forever or maybe hours?
Thanks.

Related

Limit for SSH simultaneous connection to one host

I'm trying to execute multiple SSH connection to one host but after 20 connections I've got disconnected without any particular reason.
Example test
for i in {1..30}; do ssh user#host & done
First 20 connection are ok but rest got:
kex_exchange_identification: read: Connection reset by peer
And at that time I cannot do ssh to that host for aprox few seconds.
I've tried a lot of configuration changes to /etc/ssh/sshd_config
Like:
MaxStartups
MaxSessions
ClientAliveCountMax
but nothing helps.

Powershell SSH Tunnel closes unexpectedly

I have a powershell script that keeps closing ```ssh jumpbox_user#jumpbox_ip -p 22 -L port:server_address:port -i '~/.ssh/id_rsa' -N
The issue I have is that the tunnel will start but will then, randomly, it will close. I have this issue no matter how I start the SSH tunnel. I get the feeling that it has something to do, potentially, with my home internet? I don't seem to have this issue at work or at other locations. I've purchased a new router and a new modem to no effect, is there a way to check what is going wrong???

Connect through ssh and scp and type in password automatically

I know this question has already been asked several times but I got another problem. I have a part in my script where I connect through ssh and scp and everytime I run the script it always ask for the password. Most of you would probably answer that I should use expect or sshpass yet I don't have any of this two. I tried running:
compgen -c
and there's no expect and sshpass existing.
Are there any alternative commands? I would really appreciate your help. Thanks
Update: I also can't install any of this since I'm only an ordinary user.
First I logged in to server A as testuser and entered the ff command:
ssh-keygen -d
Do not enter any passphrase.
This will generate files in the folder ~/.ssh/
Then scp the file rsa_id.pub (public key) to server B.
scp ~/.ssh/id_dsa.pub testuser#B:/home/testuser/.ssh/authorized_keys2
Do the same vice versa (if you want access to both). Then you can now transfer from one server to the other without the being asked for your password.
source
If you don't want to set up keys for passwordless access (against the rules?), you can set up "SSH connection sharing".
Insert these lines into your .ssh/config file:
ControlMaster auto
ControlPath /tmp/ssh_%r#%n:%p
ControlPersist 8h
Now, when you log into a server from the machine with that config it will ask you your password the first time, and won't ask again until 8 hours of idle time have passed (so, you'll get asked once per day, usually).
What it's doing is keeping the connection open in the background, and then reusing the same connection for all your SSH sessions. This gives a useful connect-speed boost, and means you don't need to re-authenticate. All-in-all, it's great for accelerating scripted SSH and SCP commands.

SSH drops a few seconds after connecting

I have a TP-Link MR-3020 router that is hardwired to my "real" router. The TP Link has OpenWRT installed on in and has the static IP address of 192.168.1.111 assigned to it. From my laptop, I can
ssh root#192.168.1.111 into the router.
Often times it will say
ssh: connect to host 192.168.1.111 port 22: Connection refused.
If I wait a few seconds and try again, I may get the same error or I may be prompted for the password. If I'm able to successfully log in I will often be kicked out with a broken pipe. Sometimes it's 5 seconds after logging in, sometimes it's 5 hours.
All of this is happening internally on a network and I've confirmed there aren't any other 192.168.1.111 devices out there being assigned by DHCP. What are some things I can do to debug why I keep losing my connection?
First of all, you should understand if it is SSH-only issue, or your router is rebooted / goes offline completely. To do so, start ping and watch if it work when SSH doesn't allow you to connect.
If ping works, but SSH doesn't, then watch the process id of dropbear process (ssh daemon) issuing pgrep dropbear command. If it changes, then SSH process is restarted, and it needs further investigation.
Also, post your logs (logread and dmesg command) - it might contain useful information on this issue. Try to note the time when SSH goes off and look for corresponding lines in the log.

Causing SSH to Time Out (client side)

I have a little Raspberry Pi that I'm playing with. I've got it running headless, and I need to make it forward one of its ports to a remote server when certain conditions are satisfied.
However, I don't want the connection to sit indefinitely until the server closes it. Is there a way to close an SSH connection (from the client, I have no root to the server) after a certain amount of time? Ideally I'd do it directly via the ssh command, but I'm writing in Python 3, so if there's a way to do this in Python, then I'm all ears.
In your /etc/ssh/sshd_config:
ClientAliveInterval <time interval in seconds>
ClientAliveCountMax 0
So using 300 in the first directive will kick the connection after 5 minutes idle. You'll need to restart sshd to make it take effect.
try ssh -o ServerAliveInterval=10 server.org
Unless you run ssh with the "-N" option, it normally launches some kind of command or shell on the remote system (the Pi in this case). Ssh disconnects when this remote command exits.
If you're running ssh just to create some port forwards, you may be running with "-N", or you may be letting the ssh session sit at a command prompt. Instead, you could launch a command on the Pi which exits after the desired period of time. You could use the sleep command, for example:
ssh -Lwhatever -Rwhatever user#pi "sleep 3600"