NTP time synchronization, tar backup and restore, manage users and groups, cron scheduled tasks

[NTP time synchronization, tar backup and recovery, management of users and groups, cron scheduled tasks]

NTP time synchronization
Network Time Protocol, Network Time Protocol
Time view: date
Modified time: date -s 'yyyy-mm-dd HH:MM:SS'
date -s '2008-8-8'
View time synchronization status: timedatectl
when necessary Fix: timedatectl set-ntp yes
1. Install the software package: chrony
2. Modify the configuration file: vim /etc/chrony.conf
server classroom.example.com ibusrt Specify the NTP server address
/server 172.25.254.254 iburst
3. Restart the school time service : systemctl restart chronyd[.service]
4. Set random auto-start: systemctl enable chronyd

Archive and Compress
Format: tar option archive name compressed source file 1, 2, 3
-c create file
tar -cf /opt/file.tar /etc/passwd /boot
-x free archive
-f specify archive file name
- z, -j, -J
call tools in gzip, bzip, xz format
tar -zcf /opt/test01.tar.gz /etc/passwd /boot
-P keep the absolute path of the archive
tar -zcPf /opt/test01.tar .gz /etc/passwd /boot
make tar backup package
tar -c[-cP]...
tar -zcf backup file .tar.gz backup file
tar -jcf backup file .tar.bz2 backup file
tar - Jcf backup file.tar.xz Backed up document
tar package content view
tar -tPf backup
file.tar.gz tar -tPf /root/home.tar.bz2
tar package restore file
-C Specify archive file, release location
tar - xPf backup file .tar.gz [-C destination folder]
tar -xPf /root/home.tar.bz2 -C /mnt

Manage user account
ID: UID GID
Administrator UID is always 0
Ordinary user UID starting from 1000
Add user
useradd [options]... Username
useradd karry
common command options
-u userid useradd -u 2015 nsd01
-d home directory path useradd -d /opt/haha nsd02
-s login shell
useradd -s /sbin/nologin nsd03 user nsd03 cannot log in
-g basic group
-G additional group
delete user
userdel [-r] username
userdel [-r] karry
user
id id user Name id karry
modify user attributes
usermod [options] user name
common command options
-u user id usermod -u 2017 nsd01
-d home directory path usermod -d /mnt/haha nsd02
-s login shell
-g basic group
-G additional group
settings Login password
passwd [username]
User password information is stored in the /etc/shadow file
echo 'password' | passwd --stain username
non-interactive set password
echo 123456 | passwd --stdin nsd01

Temporarily switch identity
su - username su - Student

Management group account
Group classification:
Basic group (private group): that is, a group exclusive to each user, generally only one member, the group name is the same as the corresponding user name
Additional group (public group, subordinate group): that is, multiple users share The group usually has multiple members. The group name is specified by the administrator.
Add group
groupadd [-g group ID] group name
Create group, specify GID
[root@server0 ~]# groupadd -g 3000 stugrp
[root@server0 ~]# grep 'stugrp' /etc/group View group members
Add users to groups
Create users kaka, tom, jack, natasha, kenji
[root@server0 ~]# gpasswd -a kaka stugrp add members
[root@server0 ~]# gpasswd -M 'tom,jack' stugrp add multiple members
gpasswd -M 'natasha,kenji' stugrp overwrite previous members
[root@server0 ~]# gpasswd -d tom stugrp delete members
gpasswd -d 'tom,jack' stugrp delete multiple members
[ root@server0 ~]# gpasswd -M ''stugrp Empty overwrite add, that is to delete group members
Delete group
groupdel group name groupdel stugrp
Note: the user's basic group cannot be deleted

Modify group attributes
groupmod [-g group ID] [-n new group name] group name
groupmod -g 3001 -n stugrp1 stugrp
periodic task

cron task
Purpose: to perform a fixed system task repeatedly for users at set time intervals
• Packages: cronie, crontabs
• System services: crond
• Log files: /var/log/crond

crontab Manage scheduled tasks
Edit: crontab -e [-u username]
Make a plan for the user
View: crontab -l [-u username]
View the planned plan
Clear: crontab -r [-u username]
Clear the planned
configuration File: /etc/crontab
format Time-
sharing day-month-week task command line (absolute path)
* Match any time
, separate multiple non-consecutive time points
- specify a continuous time range
/n specify a time frequency, every n ...

[root@server0 ~]# date
[root@server0 ~]# date >> /opt/time.txt
[root@server0 ~]# cat /opt/time.txt

[root@server0 ~]# crontab -e -u root
[root@server0 ~]# crontab -l -u root
* * * * * date >> /opt/time.txt Execute every minute
[root@server0 ~]# watch -n 1 cat /opt/time.txt
run cat /opt/time.txt command every second

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324888491&siteId=291194637
Recommended