- Broken pipe error on scp
- 5 Answers 5
- Fixing Broken Pipe Error With SSH Connection
- Fixing broken pipe error with SSH
- Method 1: Client side SSH configuration change
- Method 2: Server side SSH config change
- ssh connection «client_loop: send disconnect: Broken pipe» or «Connection reset by port 22»
- 4 Answers 4
- How to Fix SSH Client_loop: send disconnect: Broken pipe Error
- Client_loop: send disconnect: Broken pipe Error
- Fix Client_loop: send disconnect: Broken pipe Error
Broken pipe error on scp
I can ssh into my ubuntu box just fine, and I have already scp ‘d a version of my app onto the server, but when I run scp MaryBaked.tar.gz root@marybakedpdx.com:/home/marybakedpdx or even scp MaryBaked.tar.gz root@marybakedpdx.com:~ The progress of the scp jumps up to 81%, then the process says stalled and I get
Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/vda1 ext4 30830588 2906508 26334944 10% / none tmpfs 4 0 4 0% /sys/fs/cgroup udev devtmpfs 498088 4 498084 1% /dev tmpfs tmpfs 101788 356 101432 1% /run none tmpfs 5120 0 5120 0% /run/lock none tmpfs 508940 0 508940 0% /run/shm none tmpfs 102400 0 102400 0% /run/user
5 Answers 5
Try throttling — 2Mb/sec max throughput like so:
scp -l 2000 MaryBaked.tar.gz root@marybakedpdx.com:/home/marybakedpdx
Many times, broken pipes are caused by scp pushing/pulling too fast for something in the stack that throttling can resolve.
The problem is that the connection closed, probably because the file is too big and the session is terminated by timeout.
Solution 1: Sending back and forth keep alive messages from the server (acks) which keeps the session, Using ServerAliveCountMax and ServerAliveInterval options
scp -o ServerAliveInterval=15 -o ServerAliveCountMax=3 :~
In this example, every 15 seconds looking back for acks and if 3 acks in 45 seconds (15*3) not coming back close the session.
Look at the properties documentation below :
ServerAliveCountMax Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become unresponsive. The default value is 3. If, for example, ServerAliveInterval (see below) is set to 15 and ServerAliveCountMax is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 seconds.
ServerAliveInterval Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.
Solution 2: I can suggest you a simple workaround: compress the file , send it and extract it in your destination machine. This will short the connection time and should fix the timeout issue.
gzip bigfile.bin scp bigfile.bin.gz :~/ ssh -At cd ~ gunzip bigfile.bin.gz
Fixing Broken Pipe Error With SSH Connection
SSH connection getting disconnected due to inactivity? Here’s how to handle it.
If you use SSH to connect to remote Linux servers, you’ll notice that if you keep your SSH session inactive for some time and then try to use it again, the SSH session disconnects with an error message like this:
:client_loop: send disconnect: Broken pipe
On some systems, it will display ‘Write failed: Broken pipe’ or ‘Connection closed by remote host’.
Let’s see what causes this error and how to go about keeping your SSH connection alive.
Fixing broken pipe error with SSH
As you may have guessed, the SSH connection is closed because of inactivity. There is no set value but it usually around 5 minutes or so.
What you can do to avoid the SSH session disconnection is to send an ‘alive message’ either from the server to client ( ClientAliveInterval ) or from client to server ( ServerAliveInterval ) at certain time interval.
This way, you keep the SSH session alive because there is a communication between the client and server and the server understands that client is still there.
Now, there are two ways to do that. Either you send the alive message from the client to the server or from the server to the client.
- If you connect to multiple servers via SSH, set it on your machine.
- If you are a sysadmin and several of users complain about frequent SSH connection disconnect, you may set it on the server.
Method 1: Client side SSH configuration change
Let’s say you want to keep your SSH connection alive with up to 10 minutes (600 seconds) of idle time.
While connecting to the remote Linux system through SSH, you can mention the ServerAliveInterval value like this:
Now, this thing work but manually entering this option each time you connect to the server is tiresome. Why not make it permanent?
I hope you are aware of the SSH config files. On the client side, you can take advantage of it to set certain SSH parameters for specific connections or all of them. I have explained SSH config file in detail here.
First, make sure that you have the ssh config file. If not create it:
It is important to give it the correct file permissions otherwise you’ll have permission denied error while connecting via SSH.
Use the chmod command and add the following file permission to it:
If you’re feeling lazy or don’t want to go in detail, use this command to set the alive interval to 600 seconds (10 minutes):
echo "ServerAliveInterval 600" >> ~/.ssh/config
This will set the ServerAliveInterval value to 10 minutes for all SSH connection you’ll use. Give it a try if you want to.
If you want to make it more proper, you should add it like this:
Host * ServerAliveInterval 600
Method 2: Server side SSH config change
The SSH config file for the server is usually located at /etc/ssh/sshd_config.
If you open this file, you’ll find two parameters of interest here:
- ClientAliveInterval : This is the inactivity time period after which the server will send an alive message to the ssh connected client.
- ClientAliveCountMax : This is the number of attempts the server will make to send the alive message.
Say, you set ClientAliveInterval to 200 seconds and ClientAliveCountMax to 3. This means the server will send alive message after 200 seconds. If there is no activity from the client, it will again send an alive message at 400 seconds. No response/activity from the client and another alive message is sent at 600 seconds. After this (600 seconds) the SSH connection is disconnected.
You can edit the /etc/ssh/sshd_config file in your favorite terminal based text editor like Vim. Look for ClientAliveInterval and ClientAliveCountMax entries. Remove the # key at the beginning of the lines and give them the appropriate value.
Please do not set the SSH connection timeout to several hours. That would be a waste of resources.
I hope this tutorial helped you to fix the broken pipe error issue with SSH connection. Your feedback is welcome.
ssh connection «client_loop: send disconnect: Broken pipe» or «Connection reset by port 22»
I have been using ssh to access remote servers for many months, but recently I haven’t been able to establish a reliable connection. Sometimes I cannot login and get the message «Connection reset by port 22», when I can login I get the error message «client_loop: send disconnect: Broken pipe» in a few minutes (even if the terminal is not idle). My ~/.ssh/config file has:
Host * ServerAliveInterval 300 ServerAliveCountMax 2 TCPKeepAlive yes
#ClientAliveInterval 300 #ClientAliveCountMax 3
I recently upgraded my xfinity plan to a faster speed and the problem started happening then. But xfinity insists the issue is on my end. Note that my roommate also has the same issue with ssh. Is there something that I’m missing on my end? Any help would be greatly appreciated! (I’m running on a Mac)
4 Answers 4
I solved the same problem by editing the file ~/.ssh/config to have:
Host * ServerAliveInterval 20 TCPKeepAlive no
TCPKeepAlive no means «do not send keepalive messages to the server». When the opposite, TCPKeepAlive yes, is set, then the client sends keepalive messages to the server and requires a response in order to maintain its end of the connection. This will detect if the server goes down, reboots, etc. The trouble with this is that if the connection between the client and server is broken for a brief period of time (due to flaky a network connection), this will cause the keepalive messages to fail, and the client will end the connection with «broken pipe».
Setting TCPKeepAlive no tells the client to just assume the connection is still good until proven otherwise by a user request, meaning that temporary connection breakages while your ssh term is sitting idle in the background won’t kill the connection.
How to Fix SSH Client_loop: send disconnect: Broken pipe Error
SSH, an acronym for Secure Shell, is a remote network protocol that is used to securely connect to remote devices such as servers and network devices over a TCP/IP network.
It is a cryptographic network protocol that provides strong encryption technologies and hashing to secure communication between two devices on a network.
SSH uses two main authentication methods: password authentication and public key authentication. With password authentication, a user provides the remote host’s IP address or FQDN (Fully Qualified Domain Name) and password to authenticate.
Public key authentication uses an SSH key pair for authentication, which comprises two SSH keys: private and public keys.
The private key resides on the user’s machine and should always be kept confidential and secure. The public key is saved on the remote host that a user connects to. During authentication, the identity of the two keys is compared and access is granted.
When connecting to a remote system via SSH, you might encounter the error Client_loop: send disconnect: Broken pipe.
In this tutorial, we will see why this happens and address the error.
Client_loop: send disconnect: Broken pipe Error
The error is simply a disconnection message that notifies you that your SSH connection timeout has been exceeded.
This is a period of inactivity during which no Linux command is executed or issued from the client side. When this happens, the SSH session is terminated, effectively disconnecting you from the remote server.
Most users will usually press ‘ENTER’ or a key on the keyboard to avoid having an idle SSH session which will cause the disconnection to the host. However, this can tedious and time-wasting.
Thankfully, SSH default configuration settings provide a few parameters that you can configure to keep your SSH connections active for longer periods of time.
Fix Client_loop: send disconnect: Broken pipe Error
To resolve this issue, you need to increase the SSH connection timeout on the client. To do so, modify the default SSH configuration file which is usually at /etc/ssh/sshd_config.
$ sudo vi /etc/ssh/sshd_config
Be sure to locate these two parameters: ClientAliveInterval and ClientAliveCountMax. Let’s check out what they do.
- ClientAliveInterval – This is the period of inactivity after which the SSH server sends an alive message to the remote client that is connected to it.
- ClientAliveCountMax – This is the number of attempts that the server will make to send the alive message from the server to the client.
We will set the two values as follows:
ClientAliveInterval 300 ClientAliveCountMax 3
This means that after the first 300 seconds (5 minutes) of inactivity from the client, the server will send an alive message to the client to keep the SSH session active.
If no data or response is received from the client for the next 300 seconds (at the 600-second mark), the server will again send another alive message. Finally, after 900 seconds of inactivity from the client, the SSH connection will be terminated or dropped.
Be sure to save the changes made to the file and then exit. Then restart the SSH daemon.
$ sudo systemctl restart sshd
Alternatively, you can connect to your remote client Linux system by specifying the ServerAliveInterval parameter in seconds (300 seconds), which means your SSH session is active for up to 5 minutes.
In this tutorial, we demonstrated how to resolve the Client_loop: send disconnect: Broken pipe error. As you have seen all you need is to perform a few tweaks in the SSH configuration file.