linux系统启动过程
Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段:
- 内核的引导。
- 运行 init。
- 系统初始化。
- 建立终端 。
- 用户登录系统。
操作系统->/boot->init进程->运行级别-> /etc/init.d->用户登录->login shell
linux关机和重启
sync 将数据由内存同步到硬盘中。
shutdown 关机指令,你可以man shutdown 来看一下帮助文档。例如你可以运行如下命令关机:
shutdown –h 10 ‘This server will shutdown after 10 mins’ 这个命令告诉大家,计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。
shutdown –h now 立马关机
shutdown –h 20:25 系统会在今天20:25关机
shutdown –h +10 十分钟后关机
shutdown –r now 系统立马重启
shutdown –r +10 系统十分钟后重启
reboot 就是重启,等同于 shutdown –r now
halt 关闭系统,等同于shutdown –h now 和 poweroff
关机的命令有 shutdown –h now halt poweroff 和 init 0
重启系统的命令有 shutdown –r now reboot init 6
远程密钥登录
xsell登录工具配置:
工具-新建用户密钥生成向导-密钥类型(RSA)-密钥长度任意-生成并保存即可
服务器配置:
上传公钥(id_rsa_2048.pub)
到服务器上的~/.ssh/目录下(没有则新建),
ssh-keygen -t rsa
将公钥(Public Key)导入到“authorized_keys”文件:
cat id_rsa_2048.pub >> authorized_keys
chmod 600 authorized_keys
并命名为authorized_keys。.ssh权限必须是700,否则无法认证,authorized_keys权限为600。
vim /etc/ssh/ssh_config
PasswordAuthentication no #不允许密码验证
vim /etc/ssh/sshd_config
PermitRootLogin no #不允许root远程登录
PermitEmptyPasswords no #不允许空密码
PasswordAuthentication no #不允许密码验证
systemctl restart sshd #重启sshd服务
linux时间设置
从CentOS 7开始,使用了一个新的命令timedatectl
timedatectl 命令
(1) 读取时间
timedatectl //等同于 timedatectl status
(2) 设置时间
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
(3) 列出所有时区
timedatectl list-timezones
(4) 设置时区
timedatectl set-timezone Asia/Shanghai
(5) 是否NTP服务器同步
timedatectl set-ntp yes //yes或者no
(6) 将硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致
(1) UTC
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2) GMT
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3) CST
中国标准时间 (China Standard Time)
timedatectl set-timezone Asia/Shanghai #设置时区
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
timedatectl set-time "YYYY-MM-DD"
timedatectl set-time "HH:MM:SS"
查看linux登录日志
last -f /var/log/wtmp #查看可疑IP登陆
cat /var/log/secure #寻找可疑IP登陆次数
#脚本生成所有登录用户的操作历史
#在/etc/profile里面加入以下代码就可以实现:
PS1="`whoami`@`hostname`:"'[$PWD]'
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /tmp/authlog ]
then
mkdir /tmp/authlog
chmod 777 /tmp/authlog
fi
if [ ! -d /tmp/authlog/${LOGNAME} ]
then
mkdir /tmp/authlog/${LOGNAME}
chmod 300 /tmp/authlog/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y-%m-%d_%H:%M:%S"`
export HISTFILE="/tmp/authlog/${LOGNAME}/${USER_IP}-authlog.$DT"
chmod 600 /tmp/authlog/${LOGNAME}/*authlog* 2>/dev/null
#最后刷新配置
source /etc/profile