What’s up?

Recently, I encountered a weird problem. When I used SSH to connect to a Linux server, the connection was immediately interrupted, and such a message appeared: free(): invalid next size (fast), screenshot as below image:

image

Troubleshooting

After that, I tried to connect using another Linux computer and still had the same problem. But when I tried to connect using a Windows computer, it was able to connect this time. So I believe it is the problem of the SSH client.

image

Then, I tried to check the SSH client configuration with below command:

$ vim /etc/ssh/ssh_config

I found a suspicious item SendEnv LANG LC_* as below image:

image

So I commented out the item and tried to connect again, and this time I was able to connect without interruption immediately. But when I used the Tab key for auto-complete, it was interrupted immediately with the message realloc(): invalid next size as below image:

image

So far, you must have thought that the problem lies in the SSH client, and it has been reasonably resolved. However, this is not over yet, just imagine, some SSH clients can connect, while others still have the same problem. What a crushing thing.

Now we know that this problem is caused by the SSH environment variable, we still need to check the SSH server configuration with below command:

$ vim /etc/ssh/sshd_config

As expected, there is an item related to environment variables in the server configuration, it’s AcceptEnv LANG LC_* as below image:

image

Therefore, the best approach should be making changes of SSH server’s configuration. Regardless whether the SSH client sends environment variables, it will not cause the server connection to be interrupted immediately.

Conclusion

Stop accepting locale on the server. Do not accept the locale environment variable from your local machine to the server. You can comment out the AcceptEnv LANG LC_* line in the remote /etc/ssh/sshd_config file. Don’t forget to restart sshd to reflect the changes .