Security is a critical aspect of operating systems to protect data and resources from unauthorized access. Linux, including SUSE Linux Enterprise Server (SLES), provides various built-in security features such as file permissions, access control, firewalls, and user authentication.
Security principles in Linux:
Linux uses a file permission model to control access to files and directories.
Types of permissions:
Read (r)\*\*
: Read a file or list a directory.Write (w)\*\*
: Modify a file or add files to a directory.Execute (x)\*\*
: Run a file or access a directory.Managing file permissions:
View file permissions:
ls -l
Change file permissions:
chmod 750 file.txt
ACL allows more granular permission settings compared to the traditional permission model.
Enable ACL:
Ensure the filesystem supports ACL:
sudo mount -o remount,acl /dev/sdX1 /mnt
Basic ACL Commands:
Add ACL:
setfacl -m u:username:rwx file.txt
View ACL:
getfacl file.txt
Remove ACL:
setfacl -x u:username file.txt
SELinux and AppArmor are additional security mechanisms based on Mandatory Access Control (MAC).
SELinux:
Enforces security policies on services and applications.
Check SELinux status:
sestatus
Change SELinux mode:
sudo setenforce 0 # Permissive mode
sudo setenforce 1 # Enforcing mode
AppArmor:
AppArmor uses profiles to restrict application access.
View active profiles:
sudo aa-status
Enforce a profile:
sudo aa-enforce /etc/apparmor.d/usr.sbin.nginx
SUSE Linux supports firewalld
and SuSEfirewall2
for managing network rules.
Firewalld:
Start firewalld
sudo systemctl start firewalld
Add a rule:
sudo firewall-cmd --add-port=22/tcp –permanent
sudo firewall-cmd –reload
SuSEfirewall2:
/etc/sysconfig/SuSEfirewall2
.Restart SuSEfirewall2
:
sudo systemctl restart SuSEfirewall2
Linux manages user accounts using the /etc/passwd
and /etc/shadow
files.
Managing User Accounts:
Add a user:
sudo useradd username
sudo passwd username
Delete a user:
sudo userdel username
Lock a User Account
sudo passwd -l username
Set Password Policy:
Edit the /etc/security/pwquality.conf
file:
minlen = 12
dcredit = -1
ucredit = -1
SSH is a protocol for secure remote access.
SSH Configuration:
Install the SSH package:
sudo zypper install openssh
Start the SSH service:
sudo systemctl start sshd
Configure /etc/ssh/sshd_config
for additional security:
PermitRootLogin no
PasswordAuthentication no
Digital certificates are used to encrypt communications and verify identities.
Generate an SSH key:
Create an SSH key pair:
ssh-keygen -t rsa -b 4096
Copy the public key to the server:
ssh-copy-id user@hostname
Using OpenSSL for Certificates
Generate a private key:
openssl genrsa -out private.key 2048
Create a certificate request:
openssl req -new -key private.key -out request.csr
Create a self-signed certificate:
openssl x509 -req -days 365 -in request.csr -signkey private.key -out certificate.crt