Linux (CentOS 7) cheat sheet

Robert Andresen Uncategorized Leave a Comment

This is mostly a cheat sheet for myself that and it would be updated frequently.

Find packages

# yum list | grep ldap


systemctl [stop|start|restart|status] servicename

Change firewalld with iptables

systemctl stop firewalld<br />
systemctl mask firewalld<br />
yum install iptables-services<br />
systemctl enable iptables<br />
systemctl start iptables

Edit iptables

# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport [PORT_NUMBER_HERE] -j ACCEPT

…or edit firewalld

firewall-cmd --zone=public --add-port=[PORT_NUMBER_HERE]/tcp --permanent

Start/stop/restart Apache

systemctl stop httpd.service<br />
systemctl start httpd.service<br />
systemctl restart httpd.service

Check for running process

ps aux | grep [httpd|memcached|etc...]

Search for file

# find /search/path -iname *.conf

View files and logs

Browse a file

# more /path/to/file

Show last entry of a file

# tail /path/to/file -n 100

(use -n parameter for number of last rows)

Auto update entry from ex. log-file (use -f parameter)

# tail -f /var/log/httpd/error_log


Turn on/off SELinux

# setenforce [0|1]

Turn on/off SELinux config

# setsebool -P httpd_can_network_connect_db=1

List all possible (or search) SELinux config parameters

# getsebool -a [| grep httpd]

Set webserver permissions for file upload with SELinux and user-groups

Edit SELinux

# setsebool –P allow_httpd_anon_write=1

# chcon -R -t public_content_rw_t /var/www/

Add new group

# groupadd www-data

Change group permissions on folder

# chgrp -R www-data /var/www/

Add user to group

# usermod apache --append --groups www-data

View users in group

# grep 'www-data' /etc/group<br />


Edit a file

#vi /path/to/file

Push “a” to edit file
ESC + “:wq” for write and quit or just “:q” to quit.