
What is Linux?
Linux in its most basic form is a kernel; a low-level software interface between a computer's hardware and higher-level software. The Linux kernel is not an operating system per se, but serves as a fundamental building block for hundreds of different Linux distributions (short for 'distributions'): operating systems built on top of Linux.
There is no definitive Linux distribution, so keep that in mind throughout this guide. Each distribution has its own quirks, and the open nature of many means that new versions can be quickly created, old security issues fixed, and new ones created. Research the specific distribution and version you're interested in hardening!
Basic Linux Hardening Checklist
This section uses the Linux command line, but you do not need to be familiar with it to complete this section.
A few tips:
Take the time to research each change before implementing it! Understand the purpose of each change and what impact it will have.
Note that all the instructions below are written for Ubuntu 20.04.2.0 and may not be fully translated to other versions or distributions.
Make sure rootAccount has a Strong Password
The root account should be the most secure, so the Linux system has the most privileges!
In terminal, type sudo passwd root. Next, you will authenticate with your password and enter the new password you want to use for the root account. Don't forget this new password!
~$ sudo passwd root
[sudo] enter password for admin: ***************
New password: ********************
Retype new password: ********************
passwd: Password updated successfully
Create User Accounts for Daily Use
While it's tempting to always log in as rootuser, doing so can make it easier for attackers to compromise a system. Instead, log in with a standard user account and use the sudo command for certain command line operations that require elevated permissions.
Accounts can be created from the terminal, but it's easier to create them from the Settings app.
Open the Settings app and go to the "Users" section in the sidebar.
Unlock user settings with your password.
You can now create new accounts with the "Add User" button.
sudo Limit Privileges
sudo provides a way for user accounts to execute commands as root. This is a very powerful tool and can be very dangerous in the hands of attackers and inexperienced users. If an account doesn't need to use sudo make sure it can't use sudo.
Open the Settings app and go to the "Users" section in the sidebar.
Unlock user settings with your password.
Grant or revoke sudo privileges for each account using the "Administrator" toggle.
Check Which Services Are Running at Startup
Make sure there aren't any services that shouldn't be running automatically.
In your terminal use service --status-all to see which services start and stop:
~$ service --status-all
[ + ] apparmor
[ - ] sudo
Services marked with a + are currently running and services marked with a - have been stopped.
Uninstall Unused Software
If you're not using a piece of software, it's usually a good idea to remove it.
You can see which packages are installed using the command apt list --installed.
~$ apt list --installed
You can remove packages using the apt purge command, which removes the package along with its configuration.
~$ apt purge <package>
You can remove all unused dependencies (only packages used by other packages) using the apt autoremove command.
~$ apt autoremove
Intermediate Linux Hardening
This section contains more complex hardening techniques that have multiple steps, require greater familiarity with the Linux command line, or can cause unforeseen problems if done incorrectly. For the best experience with this, you can conveniently use the command line to create and edit configuration files.
This section includes making changes to the sudoers file that is critical to the functionality and security of Linux. When making changes to the sudoers file:
NEVER use a standard text editor to edit the sudoers file.
ALWAYS use sudoers to edit the file with visudo as it prevents the file from being saved with invalid formatting.
sudo Limit Access for Non-Admin Accounts
If a user needs sudo privileges for a certain thing, it's possible to give sudo limited access for use with certain commands.
Ensure that the user's privileges are disabled by the method described in sudo in the “Restrict Privileges” section.
Have the following information ready:
The username of the account you want to give limited permissions to.
The path to the app or apps you want to allow the account to access. (This can be easily found using the command which.)
Open a terminal and run the sudo command to log in as suroot (due to the way permissions are set, using only sudo for the following commands may not work)
~$ sudo su
Password:
sh-3.2#
Create a new file in the directory /etc/sudoers.d. (The name shouldn't matter, but you can keep things organized by giving the name of the user whose permissions you're changing)
sh-3.2# cd /etc/sudoers.d
sh-3.2# touch exampleuser
Open the file in any text editor and add the following line to the file: <username> ALL=(root) <path>. You place <username> with the path to which username and <path> you are giving permissions to the application. E.g:
exampleuser ALL=(root) /usr/bin/whoami
We will allow the user "exampleuser" whoami to run as root using sudo.
Save the file and exit the terminal.
Note that some programs can be used for what is known as privilege escalation, where they can grant a user additional permissions they shouldn't have. For example, allowing a user to run a terminal with sudo-enabled means that the user can sudo any program using sudo.
sudo Require Password to Use
Some distributions have sudo configured to have a specific time limit for use without re-entering the password. While useful, this also opens the possibility for an attacker to wait for you to use sudo and then run their own commands without authentication, taking advantage of this time.
Open the sudoers file with the command sudo visudo.
The default text editor for this is Vim, which can be difficult to use. You can run visud with an easier editor by using sudo EDITOR=nano visudo.
You should see a line that looks like this:
Defaults env_reset
Edit this line to look like this:
Defaults env_reset, timestamp_timeout=0
Save the editor and exit.
Make Sure System Updates Are Applied Regularly
Libre software has a guide for setting up automatic software updates for Ubuntu. The guide is written for the server version of the distribution, but it works for the desktop version as well.
Make sure the SSH server is Disabled or Hardened
SSH gives you access to a remote computer running an SSH server, but if you don't need to do that, it's best to disable the SSH server. If you want to learn more about hardening SSH, Tecmint has a guide on hardening OpenSSH servers.
Enforce Strong Passwords
If you share your system with other people, it's a good idea to apply strong passwords for accounts. Linux Tip has a guide for enforcing password policies in Ubuntu using PAM.
Advanced Hardening
This section is for hardening that requires a good understanding of your system and digital environment. You will need to research which techniques and practices are right for you and how to apply them.
Enable System Startup Security
Depending on when the hardware was supplied, the BIOS or UEFI is the first piece of software that runs when you start your computer. If tampered with, all subsequent programs such as the operating system can be compromised. You can start by password-protecting the configuration, disabling unused hardware ports, restricting the devices the computer can boot from, and more.
The NSA released a report in 2017 outlining the best options and recommendations for powering this part of your computer.
Encrypt System and User Files
*This usually needs to be set the first time the operating system is installed, especially to use full disk encryption. Encryption causes performance degradation on most computers because the CPU has to spend time decrypting files, but it helps protect the system from physical access.
Harden your core
The kernel is the core of the operating system, and vulnerabilities in it can leave the entire operating system open to attack. The kernel is updated regularly, so glaring flaws are unlikely, but there may be ways to make your kernel even more secure. The Arch Linux Wiki's security page has a section on kernel hardening.
Install the Firewall
The Linux kernel has a built-in firewall configured by the iptablesprogram, but it has a reputation for being difficult to use. However, UFW programs (short for "Uncomplicated Firewall") are available as a front-end to iptables, and make configuring your firewall much easier.
-TR
Linux Nedir?
Linux en temel haliyle bir çekirdektir ; bir bilgisayarın donanımı ile daha yüksek seviyeli yazılım arasında düşük seviyeli bir yazılım arayüzü. Linux çekirdeği kendi başına bir işletim sistemi değildir, ancak yüzlerce farklı Linux dağıtımı ('dağıtımlar'ın kısaltması) için temel bir yapı taşı olarak hizmet eder: Linux'un üzerine inşa edilmiş işletim sistemleri.Kesin bir Linux dağıtımı yoktur, bu yüzden bu kılavuz boyunca bunu aklınızda bulundurun. Her dağıtımın kendine özgü tuhaflıkları vardır ve birçoğunun açık doğası, yeni sürümlerin hızlı bir şekilde oluşturulabileceği, eski güvenlik sorunlarının düzeltilebileceği ve yenilerinin oluşturulabileceği anlamına gelir. Sertleştirme ile ilgilendiğiniz belirli dağıtımı ve sürümü araştırın!
Temel Linux Sertleştirme Kontrol Listesi
Bu bölüm Linux komut satırını kullanır, ancak bu bölümü tamamlamak için aşina olmanıza gerek yoktur.Birkaç ipucu:
- Uygulamadan önce her değişikliği araştırmak için zaman ayırın! Her değişikliğin amacını ve ne gibi etkileri olacağını anlayın.
- Aşağıdaki tüm talimatların Ubuntu için yazıldığını 20.04.2.0ve diğer sürümlere veya dağıtımlara tam olarak tercüme edilemeyebileceğini unutmayın.
rootHesabın Güçlü Bir Parola olduğundan emin olun
rootEn güvenli olmalıdır, böylece hesap Linux sisteminde en ayrıcalıkları vardır!- Terminalde, yazın sudo passwd root. Ardından, şifrenizle kimlik doğrulaması yapacak ve kök hesap için kullanmak istediğiniz yeni şifreyi gireceksiniz. Bu yeni şifreyi unutmayın!
~$ sudo passwd root
[sudo] enter password for admin: ***************
New password: ********************
Retype new password: ********************
passwd: Password updated successfully
Günlük Kullanım için Kullanıcı Hesapları Oluşturun
Her zaman rootkullanıcı olarak oturum açmak cazip gelse de , bunu yapmak saldırganların bir sistemin güvenliğini aşmasını kolaylaştırabilir. Bunun yerine, standart bir kullanıcı hesabıyla oturum açın ve sudokomutu, yükseltilmiş izinler gerektiren belirli komut satırı işlemleri için kullanın .- Hesaplar terminalden oluşturulabilir, ancak bunları Ayarlar uygulamasından oluşturmak daha kolaydır.
- Ayarlar uygulamasını açın ve kenar çubuğundaki "Kullanıcılar" bölümüne gidin.
- Parolanızla kullanıcı ayarlarının kilidini açın.
- Artık “Kullanıcı Ekle” butonu ile yeni hesaplar oluşturabilirsiniz.
sudoAyrıcalıkları Sınırla
sudokullanıcı hesaplarının komutları root olarak yürütmesi için bir yol sağlar. Bu çok güçlü bir araçtır ve saldırganların ve deneyimsiz kullanıcıların elinde çok tehlikeli olabilir. Bir hesabın kullanması gerekmiyorsa, kullanamayacağından sudoemin olun sudo.- Ayarlar uygulamasını açın ve kenar çubuğundaki "Kullanıcılar" bölümüne gidin.
- Parolanızla kullanıcı ayarlarının kilidini açın.
- sudoHer hesap için "Yönetici" geçişini kullanarak ayrıcalıklar verin veya iptal edin.
Başlangıçta Hangi Hizmetlerin Çalıştığını Kontrol Edin
Otomatik olarak çalışmaması gereken herhangi bir hizmet olmadığından emin olun.- Terminalinizde service --status-allhangi hizmetlerin başladığını ve durduğunu görmek için kullanın :
~$ service --status-all
[ + ] apparmor
[ - ] sudo
a +ile işaretlenen hizmetler şu anda çalışıyor ve a -ile işaretlenen hizmetler durduruldu.
Kullanılmayan Yazılımları Kaldırın
Bir yazılım parçası kullanmıyorsanız, onu kaldırmak genellikle iyi bir fikirdir.- Komutu kullanarak hangi paketlerin kurulu olduğunu görebilirsiniz apt list --installed.
~$ apt list --installed - apt purgePaketi yapılandırmasıyla birlikte kaldıran komutu kullanarak paketleri kaldırabilirsiniz .
~$ apt purge <package> - apt autoremoveKomutu kullanarak kullanılmayan tüm bağımlılıkları (yalnızca diğer paketler tarafından kullanılan paketler) kaldırabilirsiniz .
~$ apt autoremove
Orta Seviye Linux Sertleştirme
Bu bölüm, çok sayıda adımı olan, Linux komut satırına daha fazla aşinalık gerektiren veya yanlış yapılırsa öngörülemeyen sorunlara neden olabilecek daha karmaşık sertleştirme tekniklerini içerir. Bu konuda en iyi deneyim için, yapılandırma dosyalarını oluşturmak ve düzenlemek üzere komut satırını rahatça kullanabilirsiniz.Bu bölüm, sudoersLinux'un işlevselliği ve güvenliği için kritik olan dosyada değişiklik yapmayı içerir . sudoersDosyada değişiklik yaparken :
- sudoersDosyayı düzenlemek için ASLA standart bir metin düzenleyici kullanmayın .
- Dosyanın geçersiz biçimlendirme ile kaydedilmesini engellediği için dosyayı visudo düzenlemek için HER ZAMAN kullanın sudoers.
sudoYönetici Olmayan Hesaplar için Erişimi Sınırla
Bir kullanıcının sudobelirli bir şey için ayrıcalıklara ihtiyacı varsa sudo, belirli komutlarla kullanım için sınırlı erişim vermek mümkündür .
- sudo“ sudoAyrıcalıkları Sınırla ” bölümünde açıklanan yöntemle kullanıcının ayrıcalıklarının devre dışı bırakıldığından emin olun .
- Aşağıdaki bilgileri hazır bulundurun:
- Sınırlı izin vermek istediğiniz hesabın kullanıcı adı.
- Hesabın erişmesine izin vermek istediğiniz uygulama veya uygulamaların yolu. (Bu, komutu kullanılarak kolayca bulunabilir which.)
- Bir terminal açın ve sudo suroot olarak oturum açmak için komutu çalıştırın (izinlerin ayarlanma şekli nedeniyle, yalnızca sudoaşağıdaki komutlar için kullanmak çalışmayabilir)
~$ sudo su
Password:
sh-3.2# - Dizinde yeni bir dosya oluşturun /etc/sudoers.d. (Ad önemli olmamalı, ancak izinlerini değiştirdiğiniz kullanıcının adını vererek işleri düzenli tutabilirsiniz)
sh-3.2# cd /etc/sudoers.d
sh-3.2# touch exampleuser - Dosyayı istediğiniz metin düzenleyicide açın ve dosyaya şu satırı ekleyin: <username> ALL=(root) <path>. Sen yerine yerleştirir <username>izinleri vermiş olursunuz hangi kullanıcı adına ve <path>uygulamaya yol ile. Örneğin:
exampleuser ALL=(root) /usr/bin/whoami
- Kullanıcının "exampleuser" whoami kullanarak root olarak çalıştırmasına izin vereceğiz sudo.
- Dosyayı kaydedin ve terminalden çıkın.
Bazı programların, bir kullanıcının kendilerine sahip olmamaları gereken ek izinler verebildikleri, ayrıcalık yükseltme olarak bilinen şey için kullanılabileceğini unutmayın. Örneğin, bir kullanıcının bir terminali sudo etkin bir şekilde çalıştırmasına izin vermek, kullanıcının herhangi bir programı kullanarak sudo.
sudoKullanım için Parola Gerektir
Bazı dağıtımlar sudo, parolayı yeniden girmeden kullanım için belirli bir zaman sınırına sahip olacak şekilde yapılandırılmıştır . Kullanışlı olsa da, bu aynı zamanda bir saldırganın sizin kullanmanızı beklemesi ve sudoardından bu sürenin avantajını kullanarak kendi komutlarını kimlik doğrulaması olmadan çalıştırması olasılığını da açar .- Sudoers dosyasını şu komutla açın sudo visudo.
- Bunun için varsayılan metin düzenleyicisi, kullanımı zor olabilen Vim'dir. visudokullanarak daha kolay bir düzenleyici ile çalıştırabilirsiniz sudo EDITOR=nano visudo.
- Şuna benzeyen bir satır görmelisiniz:
Defaults env_reset
Bu satırı şöyle görünecek şekilde düzenleyin:
Defaults env_reset, timestamp_timeout=0 - Düzenleyiciyi kaydedin ve çıkın.
Sistem Güncellemelerinin Düzenli Olarak Uygulandığından Emin Olun
- Libre yazılımı, Ubuntu için otomatik yazılım güncellemelerini ayarlamak için bir kılavuza sahiptir . Kılavuz, dağıtımın sunucu sürümü için yazılmıştır, ancak masaüstü sürümü için de çalışır.
SSH sunucusunun Devre Dışı veya Sertleştirilmiş olduğundan emin olun
- SSH, bir SSH sunucusu çalıştıran uzak bir bilgisayara erişmenizi sağlar, ancak bunu yapmanız gerekmiyorsa, SSH sunucusunu devre dışı bırakmak en iyisidir. SSH'yi güçlendirme hakkında daha fazla bilgi edinmek istiyorsanız, Tecmint'in OpenSSH sunucularını güçlendirmeye yönelik bir kılavuzu vardır .
Güçlü Parolaları Uygulayın
- Sisteminizi başka kişilerle paylaşıyorsanız, hesaplar için güçlü parolalar uygulamak iyi bir fikirdir. Linux İpucu, PAM kullanarak Ubuntu'da parola politikalarını uygulamak için bir kılavuza sahiptir .
Gelişmiş Sertleştirme
Bu bölüm, sisteminizin ve dijital ortamınızın iyi anlaşılmasını gerektiren sertleştirme içindir. Hangi tekniklerin ve uygulamaların sizin için doğru olduğunu ve bunların nasıl uygulanacağını araştırmanız gerekecektir.Sistem Başlangıç Güvenliğini Etkinleştir
Donanımın ne zaman verildiğine bağlı olarak, BIOS veya UEFI, bilgisayarınızı başlattığınızda çalışan ilk yazılım parçasıdır. Kurcalanırsa, işletim sistemi gibi sonraki tüm programlar tehlikeye girebilir. Yapılandırmayı parolayla koruyarak, kullanılmayan donanım bağlantı noktalarını devre dışı bırakarak ve bilgisayarın önyükleme yapabileceği aygıtları kısıtlayarak ve daha fazlasıyla başlayabilirsiniz.NSA , 2017'de bilgisayarınızın bu bölümünü güçlendirmek için en iyi seçenekleri ve önerileri özetleyen bir rapor yayınladı .
Sistem ve Kullanıcı Dosyalarını Şifrele
*Bunun, özellikle tam disk şifrelemesini kullanmak için, genellikle işletim sistemi ilk kurulduğunda ayarlanması gerekir. Şifreleme, çoğu bilgisayarda performans kaybına neden olur, çünkü CPU dosyaların şifresini çözmek için zaman harcamak zorundadır, ancak sistemin fiziksel erişime karşı korunmasına yardımcı olur.Çekirdeğinizi Sertleştirin
- Çekirdek, işletim sisteminin çekirdeğidir ve içindeki güvenlik açıkları, tüm işletim sistemini saldırılara açık bırakabilir. Çekirdek düzenli olarak güncellenir, bu nedenle göze batan kusurlar olması muhtemel değildir, ancak çekirdeğinizi daha da güvenli hale getirmenin yolları olabilir. Arch Linux Wiki'nin güvenlik sayfasında çekirdek sertleştirme hakkında bir bölüm vardır.
Güvenlik Duvarını Kurun
- Linux çekirdeği, iptablesprogram tarafından yapılandırılan yerleşik bir güvenlik duvarına iptablessahiptir , ancak kullanımı zor olduğu için bir üne sahiptir. Ancak, UFW programları ("Karmaşık Olmayan Güvenlik Duvarı"nın kısaltması) için bir ön uç olarak bulunur iptablesve güvenlik duvarınızı yapılandırmayı çok daha kolaylaştırır.
Last edited by a moderator: