Install and Secure Memcached on Ubuntu 22.04
26/02/2024 - 2 phút
What is Memcached?
Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Memcached was developed by Brad Fitzpatrick in 2003. Memcached is open-source software and is distributed under the BSD license.
Install Memcached on Ubuntu 22.04
To install Memcached on Ubuntu 22.04, we will use APT, the default package manager of Ubuntu.
sudo apt update
sudo apt install memcached -y
After the installation, you can check the status of Memcached using the following command:
sudo systemctl status memcached
Secure Memcached
By default, Memcached does not have any security mechanisms. This means that anyone can connect and perform operations on the Memcached server. To secure Memcached, we will use the following methods:
Enable SASL Authentication
SASL (Simple Authentication and Security Layer) is a robust and flexible authentication protocol. SASL allows Memcached to authenticate users using a username and password.
First, we need to install the libmemcached-tools
package to use the memcstat
command:
sudo apt install libmemcached-tools -y
Finally, we will restart Memcached to apply the changes:
sudo systemctl restart memcached
Check the Status of Memcached
After the installation, you can check the status of Memcached using the following command:
sudo systemctl status memcached
Enable IP Authentication
Another way to secure Memcached is to enable IP authentication. This means that only specified IPs can connect and perform operations on the Memcached server.
First, we will open the configuration file of Memcached:
sudo nano /etc/memcached.conf
Then, we will find and edit the following line:
# Specify which IP address to listen on. The default is to listen on all IP addresses
-l 127.0.0.1
Change # Specify which IP address to listen on. The default is to listen on all IP addresses
to # Specify which IP address to listen on. The default is to listen on all IP addresses
and add your IP after -l
:
# Specify which IP address to listen on. The default is to listen on all IP addresses
-l 0.0.0.0
Finally, we will restart Memcached to apply the changes:
sudo systemctl restart memcached
Conclusion
In this article, we learned how to install and secure Memcached on Ubuntu 22.04. Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. By securing Memcached, we can prevent attacks from the outside and keep our Memcached server safe.