## 專題研究期末考小抄 :::info 此為簡略版本,付費版本內容較為詳細:https://reurl.cc/YEQE6L ::: ## 設定IP、網卡、正確日期、時間。提示符號 網卡IP設定 ![image](https://hackmd.io/_uploads/rJi-tO6VA.png) 設定日期時間 ``` date -s "2023/12/07 11:10:32" date -s "2016-11-11 10:21:32" hwclock -w #寫入 ``` 查看目前設定 ``` timedatectl ``` 提示符號設定 vim ~/.bashrc ``` export PS1="[ACS111123 孫宇衡 \A ]\\$ " ``` ![image](https://hackmd.io/_uploads/S1gSJqT40.png) ![image](https://hackmd.io/_uploads/SkDFycpV0.png) 改完後要source ``` source ~/.bashrc ``` ## httpd :個人網頁、Alias 設定 下載httpd ``` sudo yum install httpd -y ``` 啟動httpd服務 ``` sudo systemctl restart httpd ``` 開防火牆 ``` sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload ``` 設定家目錄權限 vim /etc/login.defs ``` HOME_MODE 0700 ⇒ 0711 ``` 新增公開目錄 ``` cd /etc/skel mkdir public_html ``` 新增個人網頁html ``` cd /etc/skel/public_html vim index.html ``` 設定alias ``` vim /etc/httpd/conf.d/userdir.conf ``` * 將User disable 註解# * 設定UserDir目錄名稱(public_html) ![image](https://hackmd.io/_uploads/r1swTKaER.png) userdir.conf: ``` <Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory> <Directory "/home/*/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory> ``` 新增自定義路徑(建議複製userdir.conf修改) 例: Alias 設定 /usr/share/doc/ 分享成 docs ``` cd /etc/httpd/conf.d vim doc.conf #創建doc.conf ``` doc.conf: ``` Alias /docs/ "/usr/share/doc/" <Directory "/usr/share/doc"> Options Indexes MultiViews FollowSymlinks AllowOverride None Require all granted </Directory> ``` 設定Alias後要重啟 ``` sudo systemctl restart httpd ``` > [UserDir 用戶個人網頁](https://dywang.csie.cyut.edu.tw/dywang/rhel7/node39.html) ## samba : ACL 設定, setfacl 安裝、啟動 samba ``` sudo yum install samba ``` 啟動 ``` systemctl restart smb systemctl status smb systemctl enable smb ``` 防火牆 ``` firewall-cmd --add-service=samba --permanent firewall-cmd --reload ``` 新增smb使用者 ``` pdbedit -a user_name ``` 暫時關閉 SELinux ``` setenforce 0 ``` 新增smb設定 ``` vim /etc/samba/smb.conf ``` 例: ``` [public] comment = Public path = /home/public #自己的路徑 public = yes writable = yes write list = +staff ``` 設定後需要重啟 ``` systemctl restart smb ``` 設定使用者設定 ``` setfacl -m u:<使用者>:rwx <路徑> setfacl -R -m u:sunfrancis12:rwx /home/public ``` 清除網芳所有記憶過的密碼,並中斷所有網路磁碟機, 可以在不用切換登入使用者的情況下測試。 net use * /delete ## 帳號、密碼管理。 一次設定百人帳號。 新增使用者 ``` adduser u005 ``` shell script(自建檔案並執行): ``` awk -F: -f mkuser.awk student_list | sh ``` 1. 增加 user ,設定群組,家目錄,姓名 2. 給密碼 3. 把 USER 的姓名加到 index.html 中 ```shell= {print "adduser " $3 " -g users -d /home/2024/" $3} {print " echo "$3":aaa1234 | chpasswd" } {print " echo '" $5 "' >> /home/2024/"$3"/public_html/index.html"} ``` 刪除所有使用者 ``` awk '{print "userdel -r " $3 }' student_list | sh ``` ### ping ping 全部人 ``` awk '{ print "ping -c1 "$5 }' /root/student_list | sh >> /root/ip_list ``` 查看沒ping成功的 ``` grep -B1 "Unreachable" ip_list | grep "PING" ``` 將IP對應名字 ``` grep -B1 "Unreachable" ip_list | grep "PING" | awk '{print "grep " $2 " /root/student_list"}' | sh ``` ## LVM ### fdisk 創建和切割磁碟 ``` fdisk /dev/sdb fdisk -l ``` 切割磁碟 ``` n p (enter) (enter) +2G w p ##list al ``` ![image](https://hackmd.io/_uploads/HJ4pnwHER.png) ![image](https://hackmd.io/_uploads/SkA1TDrNR.png) 將磁碟變更成LVM ``` t (enter) 8e p #list all ``` ![image](https://hackmd.io/_uploads/HyI7avHV0.png) ### pv ``` pvs pvcreate /dev/sdb1 pvs ``` ![image](https://hackmd.io/_uploads/ryMEkuS4A.png) ### vg ``` pvs vgs vgextend cs /dev/sdb1 vgs ``` ![image](https://hackmd.io/_uploads/ByiwQOHEC.png) ### lv ``` pvs vgs lvextend -L +1G /dev/cs/root vgs ``` ![image](https://hackmd.io/_uploads/SyzQH_HEA.png) > [LVM — pv, vg, lv](https://sean22492249.medium.com/lvm-pv-vg-lv-1777a84a3ce8) ### 確認變更 ``` sudo lvdisplay sudo xfs_growfs /dev/cs/root df -h | grep ^/dev ``` ![image](https://hackmd.io/_uploads/Hk_CexOH0.png)