Linux: Difference between revisions

From roonics
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 115: Line 115:


===Show journal===
===Show journal===
<pre>journalctl -xe,</pre>
<pre>journalctl -xe</pre>
 
===Add static route===
<pre>ip route add 172.26.2.54 via 172.26.2.1 dev eth0</pre>
<b>Note:</b>This clears on rebooting of the server
 
Create a file in /etc/sysconfig/network-scripts/route-eth0 with the below in the file:
<pre>172.26.0.54 via 172.26.0.1 dev eth0</pre>
This will make the route survive a rebooting of the server.
 
===Create a user===
<pre>useradd username</pre>
 
===Change password===
<pre>passwd username_you_want_to_change_password</pre>
 
===See what groups user is in===
<pre>groups username_you_want_to_check</pre>
 
===Add user to wheel (sudo) group===
<pre>usermod -a -G wheel username</pre>
 
===List users===
<pre>cat /etc/passwd</pre>
 
Example output:
<pre style="color: silver; background: black;width: 800px">
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
</pre>
 
===List groups===
<pre>cat /etc/group</pre>
 
Example output:
<pre style="color: silver; background: black;width: 800px">
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
input:x:999:
systemd-journal:x:190:
systemd-network:x:192:
dbus:x:81:
polkitd:x:998:
ssh_keys:x:997:
sshd:x:74:
postdrop:x:90:
postfix:x:89:
chrony:x:996:
apache:x:48:
mysql:x:27:
cgred:x:995:
tss:x:59:
</pre>
 
===Show group memnership===
<pre>id <username></pre>
 
Example output:
<pre style="color: silver; background: black;width: 800px">
uid=0(root) gid=0(root) groups=0(root)
</pre>
 
 
 
 




Line 122: Line 230:
[[Category:Centos]]
[[Category:Centos]]
[[Category:Redhat]]
[[Category:Redhat]]
‎<comments />

Latest revision as of 08:24, 20 March 2022

Linux

Useful Commands

Show what is listening on what port

netstat -tulpn | grep LISTEN

Example output:

tcp        0      0 0.0.0.0:5666            0.0.0.0:*               LISTEN      685/nrpe
tcp        0      0 127.0.0.1:199           0.0.0.0:*               LISTEN      958/snmpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      962/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1179/master
tcp6       0      0 :::5666                 :::*                    LISTEN      685/nrpe
tcp6     129      0 :::2224                 :::*                    LISTEN      663/ruby
tcp6       0      0 :::22                   :::*                    LISTEN      962/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1179/master

Show what version of Linux is running

cat /etc/*release

Example output:

CentOS Linux release 7.5.1804 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.5.1804 (Core)
CentOS Linux release 7.5.1804 (Core)

Show which directory is consuming how much space

du -h --max-depth=1

Example output:

13M     ./src
268K    ./.unison
20K     ./.ssh
0       ./synctest
0       ./.pki
56M     ./openssl-1.1.0f
4.0K    ./.config
68M     ./.cache
4.0K    ./.local
104M    ./vendor
262M    .

Find a file

find / -name php.ini

Example output:

/etc/php.ini

Find in a file

grep -r "localhost" /etc/php.ini

Example output:

SMTP = localhost

Tar a file

tar -cvzf outputfile.tar.gz mysql-slow.log

Untar a file

tar -zxvf outputfile.tar.gz

List all pending updates to filename called servername

Centos/Redhat:

yum list updates > /tmp/"$(uname -n).txt"

Ubuntu:

apt-get upgrade --dry-run > /tmp/"$(uname -n).txt"

Example output of servername.txt:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.econdc.com
 * epel: mirrors.coreix.net
 * extras: anorien.csc.warwick.ac.uk
 * updates: mirror.sov.uk.goscomb.net
Updated Packages
GeoIP.x86_64                           1.5.0-13.el7                      base
NetworkManager.x86_64                  1:1.12.0-8.el7_6                  updates
NetworkManager-libnm.x86_64            1:1.12.0-8.el7_6                  updates
NetworkManager-ppp.x86_64              1:1.12.0-8.el7_6                  updates
NetworkManager-tui.x86_64              1:1.12.0-8.el7_6                  updates
NetworkManager-wifi.x86_64             1:1.12.0-8.el7_6                  updates
alsa-lib.x86_64                        1.1.6-2.el7                       base
audit.x86_64                           2.8.4-4.el7                       base
audit-libs.x86_64                      2.8.4-4.el7                       base
bash.x86_64                            4.2.46-31.el7                     base
bind-libs-lite.x86_64                  32:9.9.4-73.el7_6                 updates
bind-license.noarch                    32:9.9.4-73.el7_6                 updates
binutils.x86_64                        2.27-34.base.el7                  base
centos-release.x86_64                  7-6.1810.2.el7.centos             base

Show journal

journalctl -xe

Add static route

ip route add 172.26.2.54 via 172.26.2.1 dev eth0

Note:This clears on rebooting of the server

Create a file in /etc/sysconfig/network-scripts/route-eth0 with the below in the file:

172.26.0.54 via 172.26.0.1 dev eth0

This will make the route survive a rebooting of the server.

Create a user

useradd username

Change password

passwd username_you_want_to_change_password

See what groups user is in

groups username_you_want_to_check

Add user to wheel (sudo) group

usermod -a -G wheel username

List users

cat /etc/passwd

Example output:

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin

List groups

cat /etc/group

Example output:

root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
input:x:999:
systemd-journal:x:190:
systemd-network:x:192:
dbus:x:81:
polkitd:x:998:
ssh_keys:x:997:
sshd:x:74:
postdrop:x:90:
postfix:x:89:
chrony:x:996:
apache:x:48:
mysql:x:27:
cgred:x:995:
tss:x:59:

Show group memnership

id <username>

Example output:

uid=0(root) gid=0(root) groups=0(root)

‎<comments />