日期
- 獲取當(dāng)前日期時(shí)間
date
- 設(shè)置時(shí)間
date -s "yyyy-MM-dd HH:mm:ss"
或
timedatectl set-time 'YYYY-MM-DD HH:MM:SS'
- 校準(zhǔn)時(shí)間(如本地時(shí)間不準(zhǔn))
# 開(kāi)啟后自動(dòng)校準(zhǔn)時(shí)間
sudo timedatectl set-ntp true
或
ntpdate -u(使用udp連接更新時(shí)間) ntpserver1 ntpserver2 ntpserver3
# 常用的ntp服務(wù)器
1. cn.pool.ntp.org - 這是一個(gè)多服務(wù)器群集,是國(guó)內(nèi)最常用的NTP服務(wù)器之一。
2. ntp1.aliyun.com - 阿里云提供的NTP服務(wù)器,穩(wěn)定可靠。
3. ntp2.aliyun.com - 阿里云提供的另一個(gè)NTP服務(wù)器。
4. ntp3.aliyun.com - 阿里云提供的第三個(gè)NTP服務(wù)器。
5. ntp4.aliyun.com - 阿里云提供的第四個(gè)NTP服務(wù)器。
6. ntp5.aliyun.com - 阿里云提供的第五個(gè)NTP服務(wù)器。
7. ntp6.aliyun.com - 阿里云提供的第六個(gè)NTP服務(wù)器。
8. time.windows.com - 微軟提供的全球時(shí)間服務(wù)器之一,也可以用作國(guó)內(nèi)NTP服務(wù)器。
- 格式化 date +%xx
- %Y 年
- %m 月
- %d 日
- %H 時(shí)(24小時(shí))
- %I 時(shí)(12小時(shí))
- %M 分
- %S 秒
- %s 時(shí)間戳(秒)
拼接多個(gè)字段時(shí),只需第一個(gè)字段前帶+
其他選項(xiàng),參考文檔 date --help
用戶權(quán)限
用戶
- 添加用戶
# 不指定組時(shí),默認(rèn)創(chuàng)建同名用戶組
useradd 用戶名
# 顯式指定已存在的組
useradd -g 組名 用戶名
# 自定義用戶主目錄,默認(rèn)為 /home/用戶名
useradd -d 主目錄 用戶名
- 設(shè)置密碼
passwd 用戶名
然后根據(jù)提示輸入密碼即可
- 查看用戶信息
id 用戶名
- 查看所有用戶
cat /etc/passwd
-
切換用戶
- su 用戶名(切換后,只能獲取用戶執(zhí)行權(quán)限,無(wú)法獲取用戶特有環(huán)境變量)
- su-用戶名(切換后,獲得用戶執(zhí)行權(quán)限和用戶特有環(huán)境變量)
-
修改用戶(修改其他屬性參考幫助文檔)
# 修改用戶組
usermod -g 組名 用戶名
- 刪除用戶
# 保留用戶主目錄
userdel 用戶名
# 不保留用戶主目錄
userdel -r 用戶名
用戶組
創(chuàng)建用戶時(shí),如果沒(méi)有指定用戶組,則默認(rèn)創(chuàng)建同名組;
組信息都在 /etc/group 中文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-641894.html
- 創(chuàng)建組
groupadd 組名
- 刪除組
groupdel 組名
- 修改組
groupmod -n 新組名 原有組名
用戶權(quán)限
- 普通用戶以root權(quán)限執(zhí)行命令
sudo xxxx
想要執(zhí)行sudo 操作,需要root用戶事先將 需要使用sudo的用戶添加到 sudoers 列表中 /etc/sudoers 參考root用戶,增加一行對(duì)應(yīng)用戶的配置。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-641894.html
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
用戶名 ALL=(ALL) ALL
- 給用戶組設(shè)置 sudo 權(quán)限
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
%組名 ALL=(ALL) ALL
到了這里,關(guān)于Linux 基礎(chǔ)(四)常用命令-日期 & 用戶權(quán)限的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!