CentOS

Contents
Introduction
Install CentOS
Postinstall Setup
Check CentOS version
yum: install software
wheel: get access to sudo
install Golang
sh commands
File Types
passwd: change user's password
Check Locale
Modify Locale
More about CentOS

Introduction

CentOS - Community ENTerprise Operating System — Linux distribution based on commercial Red Hat Enterprise Linux of Red Hat company and compatible with it.

According to the Red Hat Enterprise Linux (RHEL) lifecycle , CentOS 5, 6 and 7 will be supported for "up to 10 years" as they are based on RHEL.

Previously, the CentOS 4 version was supported for seven years.

Red Hat Enterprise Linux consists of free software with open source, but available as disks with binary packages only for paid subscribers.

As required by the GPL license and others, Red Hat provides all source codes.

CentOS developers use this source code to create the final product, very close to Red Hat Enterprise Linux and available for download.

CentOS Installation

You can download CentOS image from www.centos.org

CentOS 7 download site image from website www.aredel.com
Mirror for CentOS 7 Downlod

You can read about writing images to USB card in the «UltraISO» article.

Check how to isntall CentOS 7 VirtualBox in «CentOS installation on VirtualBox» manual.

Postinstall Setup

My advise is to run

sudo yum -y update
yum install -y redhat-lsb-core net-tools epel-release kernel-headers kernel-devel
yum groupinstall -y "Development Tools"

If you need to turn network interface automatically after boot:

sudo sed -i s/ONBOOT=no/ONBOOT=yes/ /etc/sysconfig/network-scripts/ifcfg-enp0s3

Check current release version

You can check CentOS version by running

cat /etc/system-release

CentOS Linux release 7.9.2009 (Core)

Or (from CentOS 6)

cat /etc/centos-release

CentOS Linux release 7.9.2009 (Core)

Also from CentOS 6 you can use

rpm -q centos-release

centos-release-7-9.2009.0.el7.centos.x86_64

If you have installed redhat-lsb package you can use

lsb_release -a

\LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.9.2009 (Core) Release: 7.9.2009 Codename: Core You have new mail in /var/spool/mail/andrei [andrei@demoad ~]$ lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.9.2009 (Core) Release: 7.9.2009 Codename: Core

If you are interested only in the major version

lpm -E %{rhel}

7

Or

rpm --eval %{centos_ver}

7

Software Installation

Для начала неплохо обновить пакетный менеджер. В CentOS он называется yum

yum update

Для тихой установки use flag -y

yum install -y redhat-lsb-core net-tools epel-release kernel-headers kernel-devel

yum groupinstall -y "Development Tools"

To install the graphical shell execute command

yum groupinstall -y "X Window System" "MATE Desktop"

Add a user to the sudo group

All users from the wheel group have the ability to execute the command sudo therefore, you need to become root.

su

And as root, add the user to the wheel group with the command

usermod -aG wheel andrei

You can become a user again by doing

su andrei

Network Configuration

Considered in a separate article - «Configuring network connections in CentOS»;

Installing wget

sudo yum install wget

Installing Go

Download Golang it is possible from the website golang.org

wget https://golang.org/dl/go1.15.5.linux-386.tar.gz

After downloading, check that the checksum matches the one recorded on the site

sha256sum go1.15.5.linux-386.tar.gz

4c8179d406136979724c71732009c7e2e7c794dbeaaa2a043c00da34d4be0559 go1.15.5.linux-386.tar.gz

Matches the value on the site - look at the bottom line

Install image via network VirtualBox image from website www.aredel.com

Unpack the archive

sudo tar -C /usr/local -xzf go1.15.5.linux-386.tar.gz

Add the path to go to PATH

vi ~/.bash_profile

export PATH=$PATH:/usr/local/go/bin

Create a working directory

mkdir ~/go

Check if GoLang is installed

go version

If you received something like this

go version go1.15.5 linux/386

Then everything is fine

If you received an error

-bash: /usr/local/go/bin/go: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Try installing glibc.i686

sudo yum install glibc.i686

Installing X

Installation and configuration of the X server are reviewed in a separate article - "X Window System in CentOS";

Useful commands

Moving between X and the real terminal (physical terminal) is done by pressing the right CTRL + F2 - to go to the console

Right CTRL + F1 - to go to x

To find out the name of your execute console

tty

/dev/pts/0

To find out who is connected to the execute system

who

andrei tty1 2020-11-19 11:03 (:0) andrei pts/0 2020-11-19 11:45 (:0) andrei tty2 2020-11-19 11:42 andrei pts/1 2020-11-19 11:48 (192.168.56.1)

tty1 and tty2 are real terminals

pts/0 is a pseudo terminal running in lawsuits on a local machine

pts/1 is a pseudo terminal on a remote machine with IP 192.168.56.1 from which I connected via ssh

In Linux everything is files and tty terminals are no exception.

Execute

ls -l $(tty)

Or a similar command

ls -l /dev/pts/1

crw--w----. 1 andrei tty 136, 1 Nov 19 12:43 /dev/pts/1

The first character is the file type.

There are seven file types available: regular, directories, symbolic, blocks, sockets, named pipes, symbolic links

- : regular file
d : directory
c : character device file
b : block device file
s : local socket file
p : named pipe
l : symbolic link

Type c means character. That is, this file can accept and show characters

If you run

ls -ld /etc

drwxr-xr-x. 118 root root 8192 Nov 19 11:02 /etc

It can be seen that the file type is d. That is, directory

To view disks/execute blocks

lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6.2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sr0 11:0 1 57.7M 0 rom /run/media/andrei/VBox_GAs_6.1.10

If you run

ls -l /dev/sda*

brw-rw----. 1 root disk 8, 0 Nov 19 11:02 /dev/sda brw-rw----. 1 root disk 8, 1 Nov 19 11:02 /dev/sda1 brw-rw----. 1 root disk 8, 2 Nov 19 11:02 /dev/sda2

You can make sure that the file type is b. That is, block

? means that there must be one of any character.

ls -l /dev/sda?

brw-rw----. 1 root disk 8, 1 Nov 19 11:02 /dev/sda1 brw-rw----. 1 root disk 8, 2 Nov 19 11:02 /dev/sda2

[12] means that there must be either a character 1 or a character 2

ls -l /dev/sda[12]

brw-rw----. 1 root disk 8, 1 Nov 19 11:02 /dev/sda1 brw-rw----. 1 root disk 8, 2 Nov 19 11:02 /dev/sda2

When you want to find out the system version, you can run

ls -l /etc/system-release

lrwxrwxrwx. 1 root root 14 Nov 17 13:44 /etc/system-release -> centos-release

File type l means link that is, it is not a real file, but a link

Execute

ls -l /etc/system-release /etc/centos-release /etc/redhat-release

-rw-r--r--. 1 root root 37 Oct 23 17:53 /etc/centos-release lrwxrwxrwx. 1 root root 14 Nov 17 13:44 /etc/redhat-release -> centos-release lrwxrwxrwx. 1 root root 14 Nov 17 13:44 /etc/system-release -> centos-release

/etc/centos-release - this is a real (regular) file and the rest are links to it.

If you were using red hat, the real one would be redhat-release

Another way to get version information is to execute lsb_release -d where -d means description

lsb_release -d

Description: CentOS Linux release 7.9.2009 (Core)

To find out where the lsb_release file is located, use the which lsb_release command. To get it right away for more information, execute

ls -lF $(which lsb_release)

-rwxr-xr-x. 1 root root 15929 Mar 27 2015 /usr/bin/lsb_release*

The -F option means to show the file type. Therefore, we were able to see * after lsb_release. * means that the file executable.

To find out where the file came from, you can use the rpm command with options q (query) and f (file)

rpm -qf $(which lsb_release)

redhat-lsb-core-4.1-27.el7.centos.1.x86_64

To copy the file interactively, use the command cp with the option i (interactive)

interactive means that if a file with that name exists, you will be asked before overwriting it.

cp -i /etc/hosts .
cp -i /etc/hosts .

cp: overwrite ‘./hosts’?

To create a directory immediately with a subdirectory inside, use the command mkdir with option p (parent)

mkdir -p sites/heiheiruru
ls -l sites

total 0
drwxrwxr-x. 2 andrei andrei 6 Nov 19 13:40 heiheiru

To create multiple files at the same time with names following the order execute touch with {}

touch files/file{1..5}
ls -l files

-rw-rw-r--. 1 andrei andrei 0 Nov 19 13:46 file1 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:46 file2 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:46 file3 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:46 file4 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:46 file5

To copy the files directory to the sites directory with all the contents of execute

cp -R files sites
ls -l sites/files/

total 0 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:49 file1 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:49 file2 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:49 file3 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:49 file4 -rw-rw-r--. 1 andrei andrei 0 Nov 19 13:49 file5

The files directory was copied to the sites directory, so now sites has the files subdirectory.

If you have the tree module installed, you can visually examine the nesting. If not, execute sudo yum install tree first

tree sites

sites └── files ├── file1 ├── file2 ├── file3 ├── file4 └── file5 1 directory, 5 files

You can create a link with the command ln, a symbolic link ln -s

You can clear the terminal by pressing CTRL + l

To study the details of your SSH connection, you can use the command

echo $SSH_CONNECTION

192.168.56.1 52350 192.168.56.101 22

First come the client's IP and port, then the server's IP and port

To examine the contents of a long execute test file

less filename

To search forward, press / to search backward ?

Search

Simple find

find /usr/share/doc -name '*.pdf'

Find and immediately copy to the current directory

find /usr/share/doc -name '*.pdf' -exec cp {} . \;

Find in the current directory

find -name '*.pdf'

Delete from current directory

find -name '*.pdf' -delete

Find all links

find /etc -type l

Find all links only at the top level of nesting

find /etc -maxdepth 1 -type l

df -h /boot

Filesystem Size Used Avail Use% Mounted on /dev/sda1 1014M 194M 821M 20% /boot

Find regular files of a certain size

find /boot -size +20000k -type f

find: ‘/boot/efi/EFI/centos’: Permission denied find: ‘/boot/grub2’: Permission denied /boot/initramfs-0-rescue-389ee10be1b38d4281b9720fabd80a37.img /boot/initramfs-3.10.0-1160.el7.x86_64.img /boot/initramfs-3.10.0-1160.2.2.el7.x86_64.img

find /boot -size +10000k -type f

find: ‘/boot/efi/EFI/centos’: Permission denied find: ‘/boot/grub2’: Permission denied /boot/initramfs-0-rescue-389ee10be1b38d4281b9720fabd80a37.img /boot/initramfs-3.10.0-1160.el7.x86_64.img /boot/initramfs-3.10.0-1160.el7.x86_64kdump.img /boot/initramfs-3.10.0-1160.2.2.el7.x86_64.img /boot/initramfs-3.10.0-1160.2.2.el7.x86_64kdump.img

The same plus show the size of the files

find /boot -size +10000k -type f -exec du -h {} \;

find: ‘/boot/efi/EFI/centos’: Permission denied find: ‘/boot/grub2’: Permission denied 60M /boot/initramfs-0-rescue-389ee10be1b38d4281b9720fabd80a37.img 21M /boot/initramfs-3.10.0-1160.el7.x86_64.img 13M /boot/initramfs-3.10.0-1160.el7.x86_64kdump.img 21M /boot/initramfs-3.10.0-1160.2.2.el7.x86_64.img 14M /boot/initramfs-3.10.0-1160.2.2.el7.x86_64kdump.img

Change the user's password

To in CentOS change the user's password execute command passwd

[andrei@localhost ~]$ sudo passwd andrei

[sudo] password for andrei:
Changing password for user andrei.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

locale

To find out current CentOS locale

cat /etc/locale.conf

LANG="en_US.UTF-8"

or

localectl status

System Locale: LANG=en_US.UTF-8 VC Keymap: us X11 Layout: us

List of available locales

localectl list-locales

aa_DJ aa_DJ.iso88591 aa_DJ.utf8 aa_ER aa_ER.utf8 aa_ER.utf8@saaho aa_ER@saaho aa_ET aa_ET.utf8 af_ZA af_ZA.iso88591 af_ZA.utf8 am_ET am_ET.utf8 an_ES an_ES.iso885915 an_ES.utf8 ar_AE ar_AE.iso88596 ar_AE.utf8 ar_BH ar_BH.iso88596 ar_BH.utf8 ar_DZ ar_DZ.iso88596 ar_DZ.utf8 ar_EG ar_EG.iso88596 ar_EG.utf8 ar_IN ar_IN.utf8 ar_IQ

Choose English only

localectl list-locales | grep en_US

en_US en_US.iso88591 en_US.iso885915 en_US.utf8

The list of system variables associated with the locale is available by the command

locale

LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE="en_US.UTF-8" LC_MONETARY=en_US.UTF-8 LC_MESSAGES="en_US.UTF-8" LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 LC_ALL=

Detailed information on each variable can be obtained using flags -c -k

locale -c -k LC_TIME

LC_TIME abday="Sun;Mon;Tue;Wed;Thu;Fri;Sat" day="Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday" abmon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec" mon="January;February;March;April;May;June;July;August;September;October;November;December" am_pm="AM;PM" d_t_fmt="%a %d %b %Y %r %Z" d_fmt="%m/%d/%Y" t_fmt="%r" t_fmt_ampm="%I:%M:%S %p" era= era_year="" era_d_fmt="" alt_digits= era_d_t_fmt="" era_t_fmt="" time-era-num-entries=0 time-era-entries="S" week-ndays=7 week-1stday=19971130 week-1stweek=7 first_weekday=1 first_workday=2 cal_direction=1 timezone="" date_fmt="%a %b %e %H:%M:%S %Z %Y" time-codeset="UTF-8"

locale -c -k LC_CTYPE

LC_CTYPE ctype-class-names="upper";"lower";"alpha";"digit";"xdigit";"space";"print";"graph";"blank";"cntrl";"punct";"alnum";"combining";"combining_level3" ctype-map-names="toupper";"tolower";"totitle" ctype-width=16 ctype-mb-cur-max=6 charmap="UTF-8" ctype-class-offset=72 ctype-map-offset=86 ctype-indigits_mb-len=1 ctype-indigits0_mb="0" ctype-indigits1_mb="1" ctype-indigits2_mb="2" ctype-indigits3_mb="3" ctype-indigits4_mb="4" ctype-indigits5_mb="5" ctype-indigits6_mb="6" ctype-indigits7_mb="7" ctype-indigits8_mb="8" ctype-indigits9_mb="9" ctype-indigits_wc-len=1 ctype-outdigit0_mb="0" ctype-outdigit1_mb="1" ctype-outdigit2_mb="2" ctype-outdigit3_mb="3" ctype-outdigit4_mb="4" ctype-outdigit5_mb="5" ctype-outdigit6_mb="6" ctype-outdigit7_mb="7" ctype-outdigit8_mb="8" ctype-outdigit9_mb="9" ctype-outdigit0_wc=48 ctype-outdigit1_wc=49 ctype-outdigit2_wc=50 ctype-outdigit3_wc=51 ctype-outdigit4_wc=52 ctype-outdigit5_wc=53 ctype-outdigit6_wc=54 ctype-outdigit7_wc=55 ctype-outdigit8_wc=56 ctype-outdigit9_wc=57 ctype-translit-tab-size=4554 ctype-translit-default-missing-len=1 ctype-translit-ignore-len=0 ctype-translit-ignore="" map-to-nonascii=0

List of available locales

locale -a

Modify locale

To change the locale in CentOS, you can either edit the file locale.conf in /etc/ or use the localect command (starting from CentOS 7)

Suppose we need to change the locale to en_us.iso88591

Open locale.conf and find the string LANG

sudo vi /etc/locale.conf

LANG="en_US.UTF-8"

Replace UTF-8 with iso88591

LANG="en_US.iso88591"

Alternative method using sed - execute command

sudo sed -i s/LANG=\"en_US\.UTF-8\"/LANG=\"en_US\.iso88591\"/ /etc/locale.conf

To check the changes execute

localectl status

System Locale: LANG=en_US.iso88591 VC Keymap: us X11 Layout: us

To change a system variable, for example, LC_CTYPE execute

sudo vi ~/.bashrc

And enter the following code at the end of the file

LC_CTYPE="en_US.iso88591" export LC_CTYPE

locale -c -k LC_CTYPE

LC_CTYPE ctype-class-names="upper";"lower";"alpha";"digit";"xdigit";"space";"print";"graph";"blank";"cntrl";"punct";"alnum";"combining";"combining_level3" ctype-map-names="toupper";"tolower";"totitle" ctype-width=16 ctype-mb-cur-max=1 charmap="ISO-8859-1"

Related Articles
CentOS
Network Configuration
Firewall
iftop: Network Monitoring
nethogs: Network Monitoring
tc: Traffic Control
iperf: Network Performance
Date Time
X Window System CentOS
XRDP: Remote Desktop
VNC: Remote Desktop
Change machine-id
Change ulimit
xclip: Buffer
docker-ce: install in CentOS 8
FAQ
Errors
Install virtual CentOS on Ubuntu
Docker container CentOS with SSH access
Files
Combine .pdf Files
diff: Compare Files
find: Search for Files
kill: Finish Process
make
signal
env
localectl
systemctl: List Active Services
SCP: File Exchange
SSH: Remote Access
cron
sudo