SSH is one of the most used tools by us and by most developers. In this blog we share a number of tips that make SSH both more secure and efficient. These tips are not only applicable to our high performance web servers, but also to your own internal servers. We assume that you are using a recent version of OpenSSH (both client and server). In the examples we use "d-example.host-ed.eu" as the server address. Replace this with your own server address.
What is SSH?
SSH stands for Secure Shell and allows you to log in to another computer or server remotely in a secure, encrypted way. This allows you to work on the machine you are logged in to and exchange data securely. Because the connection is encrypted, malicious parties cannot simply intercept your passwords.
How do you use SSH?
SSH enables secure communication between computers or servers. To use SSH, first download an SSH client, which allows you to generate an SSH key. After that, you can connect to other servers, provided your hosting provider supports SSH. At LinQhost, we are happy to help you with the installation of SSH, so feel free to contact us for more information.
Tips for a better SSH experience
Tip 1: Call MySQL server remotely via SSH
Want to access your database from a remote location without compromising security? A simple and secure solution is to set up a MySQL tunnel via an SSH connection. On your local machine, enter the following command:
ssh -L 3307:127.0.0.1:3306 your_user@d-example.host-ed.eu -p 22622
This command allows you to connect locally to the MySQL server using port 3307, while the SSH tunnel makes the communication secure.
Tip 2: Improve your OpenSSH server encryption
The default configuration of OpenSSH is often quite lenient, meaning that obsolete algorithms such as SHA1 are still allowed. SHA1 is considered
insecure and you do not want to use it. To improve your security, adjust the configuration by adding the following lines to the sshd_config file:
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
Don't forget to restart your OpenSSH server after making these changes!
The result should then look something like this:
Tip 3: Use ECDSA for better performance
Traditionally, SSH-RSA is used to establish secure connections, but this requires a lot of processing power, especially with keys of 4096 bits. An alternative is to use ECDSA, a key type that provides the same security with fewer bits. You can generate an ECDSA key with the following command:
ssh-keygen -t ecdsa -b 521
This will ensure faster connections and better performance, especially when using recent SSH clients.
Tip 4: Turn on compression for faster connections
Many people forget that you can speed up your data connection by enabling compression during your SSH session. This is especially useful on slow connections. Add the -C parameter to your SSH command to enable compression:
ssh -C d-example.host-ed.eu -p 22622
If you want to enable compression by default, add the line Compression yes to your SSH configuration file (~/.ssh/config).