Linux 隨手記 3

1. 手動清除 Linux 記憶體快取

echo 1 > /proc/sys/vm/drop_caches <== 清除 pagecache

echo 2 > /proc/sys/vm/drop_caches <== 清除 dentries 與 inodes

echo 3 > /proc/sys/vm/drop_caches <== 1 + 2

註1:root 才能操作
註2:最好先 sync 過
註3:不要隨意使用,有可能會造成資料遺失

參考資料:
Yu-Hsin Hung 大的文章
https://medium.com/hungys-blog/clear-linux-memory-cache-manually-90bec95ea003

yichun 大口述 


2. owasp zap 操作說明

他是一個網頁滲透試工具,有時也會拿來做為黑箱測試工具

參考資料:Alison Cheang 文章
http://www.manetic.org/index.php?option=com_content&id=4216:owasp-zap&Itemid=301&lang=en   


3. 紀錄使用者操作

在 Linux 系統中,會自動將使用者的操作紀錄寫入 .bash_history,不過這個檔案沒有時間紀錄、沒有即時性,不易閱讀,而且有保留的上限。那是否可以做到即時記錄、有時間紀錄且可以分檔保留,可以在 .bashrc 中寫入以資訊,就可以做到了,也可以建一個檔到 /etc/profile.d/ 讓使用者預設就是會寫操作紀錄

補充:不過這樣的方式使用者還是可以自行刪除檔案

export PROMPT_COMMAND='echo "$(date "+%Y-%m-%d;%H:%M:%S.%3N") $(whoami) $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log;'

註1:這個方式可通用於 CentOS 及 ubuntu
註2:如果要檔案不被刪除,可以修改檔案格式,使用 chattr -a 讓檔案變為可寫不可刪

資料來源:
yi 口述

GTW 文章
https://blog.gtwang.org/linux/how-to-make-file-immutable-on-linux-chattr-command/

Tsung 文章 -- Bash history 加上 日期和時間
https://blog.longwin.com.tw/2017/05/linux-bash-history-date-time-display-2017/


4. rm 指令

一個非常常用且危險的指令

rm -rf {*,.*} => 刪除該層所有檔案含隱藏檔

Brian 大口述


5. vimrc 檔案中的設定,如何 mark 掉

在這個檔案中不能使用 # ,要使用 "

參考資料:
有心故我在
https://www.cnblogs.com/youxin/archive/2013/04/08/3007220.html

TU大
http://qbsuranalang.blogspot.com/2015/01/vim.html 

補充:常用的設定
set encoding=utf-8
set wildmenu
set showcmd
set hlsearch
set number
set history=50
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set ruler
set autoindent
set paste
set fileformats=unix
map Y y$
"set backup
"if has('mouse')
"set mouse=a
"endif
filetype plugiin indent on

資料來源:小雨大

其他資料:
鳥哥
http://linux.vbird.org/linux_basic/0310vi/0310vi.php

某大
http://www2.nsysu.edu.tw/csmlab/unix/vi_simple.htm
http://www2.nsysu.edu.tw/csmlab/unix/vi_command.htm


6. 使用 checksum 來保證檔案的正確性

檔案在傳遞過程中有可能有竄改、缺失等可能性,透過 checksum 方式,可以保證檔案的正性

使用方式 md5sum [檔名] ,就會算出一串數字,核對兩個檔案的數字,就可以確認正確性了

參考資料:GTW
https://blog.gtwang.org/linux/generate-verify-check-files-md5-sha1-checksum-linux/  


7. ChromeCast 設定

 

參考資料:電腦王阿達
https://www.kocpc.com.tw/archives/242068  


8. watch 指令

watch -n 10 'ls |wc -l' <= 每10秒執行一次查看目錄檔數案指令

資料來源:

brian大 


9. filebeat 執行時出現錯誤訊息

在執行 filebeat 時,讀取 filebeat.yml 檔,出現了以下錯誤訊息
Exiting: error loading config file: config file ("{beatname}.yml") must be owned by the beat user (uid=501) or root

這個是 filebeat 進行的檢查config file 權限檢查,如果要忽略,可以加 -strict.perms=false 這個參數,不過官方建議不要忽略,towns 則是另建一個 filebeat 的帳號來執行

參考資料:andrewkroh 大的回應
https://www.elastic.co/guide/en/beats/libbeat/5.3/config-file-permissions.html#_disabling_strict_permission_checks 


10. notepad++ 存檔時去除行尾空白

巨集 => Trim Trailing and save

參考資料:laravel 大說明
https://segmentfault.com/q/1010000002576171/a-1020000002591746 


11. DNS cache client 端管理

ubuntu
1. systemd-resolve --statistics <= 檢查目前快取資料
2. systemd-resolve --flush-caches <= 清除快取
3. systemd-resolve --statistics <= 檢查目前快取資料

在 ubuntu 中還有其他方式

Centos 7
systemctl restart dnsmasq.service

參考資料:
FOSSLINUX
https://www.fosslinux.com/9131/how-to-flush-dns-on-ubuntu-and-centos.htm  


12. 鑰匙圈

鑰匙圈的用途就是記住如網站、信箱、AD 等密碼,可以讓使用者在下次使用時,不需要再打入密碼,但一但改過密碼後,就會要求更新鑰匙圈的密碼,這個真的是有點麻煩呢!towns 不習慣將密碼記在系統中
在 Gnome 3 中,開啟 Chrome 時,鑰匙圈會要求解鎖,為什麼 FireFox 不會啊?

參考資料
玩物尚誌大文章 -- 停用 Ubuntu 13.04 自動登入的鑰匙圈密碼提示
http://blog.lyhdev.com/2013/10/ubuntu-1304.html 


13. 安裝額外的字型

1. 取得指定字型
2. 放入 /usr/share/fonts/[自定目錄]
3. 安裝字型
fc-cache -v /usr/share/fonts/[自定目錄]
4. 確認是否安裝
fc-list

參考資料:
小雨大文章
https://ithelp.ithome.com.tw/questions/10144653


14. 關閉 Linux Gnome 電源鍵

 

參考資料:stackexchange -- James Henstridge 回應
https://askubuntu.com/questions/93542/how-to-disable-shutdown-reboot-suspend-hibernate


15. Oracle Linux 安裝 docker 問題

會缺 container-selinux 這個套件,而且,預設官方是不提供的,必需手動加入 OL7 Add-ons repo

vi /etc/yum.repos.d/ol7_addons.repo
[ol7_addons]
name=Oracle Linux $releasever Add ons (\$basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL7/addons/\$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1

註:dcode 大給的是一個 script,會更方便使用

參考資料:
dcode 大大的 github
https://gist.github.com/dcode/f6a5c9cd48ce68e0c355  


16. 使用 python 建立加密密碼

1. 使用 python
python -c 'import crypt,getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))'

這個密碼產生的結果,與在 CentOS 下使用 passwd 建立的密碼是相同的

2. 使用 mkpasswd
mkpasswd --method=sha-512
註:在 CentOS 7 下必需安裝 expect 套件

參考資料:yi大 


17. ClamAV for Linux 安裝操作說明

安裝後先執行
1. 手動執行 freshclam 更新病毒碼
2. 啟動自動下載
3. 設定開機啟動 clamav-freshclam

相關資料
自動更新設定檔位置 /etc/freshclam.conf(CentOS 7)
自動更新設定檔位置 /etc/clamav/freshclam.conf(ubuntu 16.04)
DatabaseDirectory /var/lib/clamav
病毒碼更新 log 檔位置 /var/log/freshclam.log(CentOS 7)
病毒碼更新 log 檔位置 /var/log/clamav/freshclam.log(ubuntu 16.04)

手動更新病毒碼
1. 連接到官網下載 bytecode.cvd、daily.cvd、main.cvd
2. 將檔案放到 /var/lib/clamav/

手動產生設定檔(如果安裝後設定檔不存在)
執行 /usr/bin/clamconf(CentOS 7)

設定檔修改(freshclam.conf)
一般會先確認
1. UpdateLogFile 是否有設定
2. DatabaseMirror 加入穩定的更新來源
3. DatabaseDirectory 路徑

參考資料:
甘蔗大的文章
https://blog.xuite.net/tolarku/blog/302285776-Linux+%E7%B3%BB%E7%B5%B1%E5%AE%89%E8%A3%9D%E9%98%B2%E6%AF%92+-+ClamAV+-+CentOS

https://blog.xuite.net/tolarku/blog/543961253-CentOS7+%E5%AE%89%E8%A3%9D%E9%98%B2%E6%AF%92%E8%BB%9F%E9%AB%94+ClamAV

官網下載
https://www.clamav.net/downloads  


18. 強制將使用者踢出 gnome

測試結果,只要將登入 gnome 的 session kill 掉,所有在 gnome 下的程序,就會全部刪除
ps aux |grep [username]
kill -9 [PID]
*****  41363  0.0  0.0 745452 14396 ?        Sl    6月20   0:05 /usr/libexec/gnome-session-binary --session=gnome-classic


19. 開源的IP管理系統 -- phpIPAM

 

參考資料:
節省哥 -- 開源 IP 位址管理系統:phpIPAM
https://ithelp.ithome.com.tw/articles/10222268?sc=hot   


20. 指令 mkdir

mkdir -p /a/b/c/d <= 產生一串 /a/b/c/d 目錄,
-p parents,no error if existing, make parent directories as needed


21. nfs server 設定

在 CentOS7 為了可以 mount NAS 的 nfs 下安裝了 nfs-utils,不過,這個套件會加裝 15 套件及新增15服務,還會開啟很多 port(TCP 111、UDP),難掌握呢!client 主要還是 rpc 服務

參考資料:

it邦幫忙 -- willion0736 大文章
https://ithelp.ithome.com.tw/articles/10078793

瀚海揚塵大的文章
http://ylin77.blogspot.com/2010/07/nfsport.html

it邦幫忙 -- weithenn 大文章
https://ithelp.ithome.com.tw/articles/1008110


22. jq 套件

這個套件用於將 json 格式的檔案,以陣列方式排列,會比較容易閱讀

jq ".[]|{protocol,address,port}" [檔名]
陣列,取protocol、address、port 排列

註:要有安裝 jq 套件

參考資料:
James 大口述 


23. CentOS 7 安裝 Python 3.7

註:在 make install 後,會提醒需將 /usr/local/python3/bin 路徑加入

參考資料:
懶大 -- 在CentOS 7安裝Python 3.7
https://blog.jiebu-lang.com/centos-7-install-python-3-7/ 


24. vim 中的區塊選擇及區塊寫入

ctrl + v => 區塊選擇
shift + i => 選擇寫入區塊
於區塊第一行打入要加的字元
ESC 寫入區塊
補充:使用 ctrl + v 後,可以使用其他按鍵,如刪除區塊中的文字,選取後按 x

參考資料:
James 大口述 

鳥哥 -- vim
http://linux.vbird.org/linux_basic/0310vi.php#vim_v

------------------------------------------------------------------------------------------------------

vim 中的文字取代

先按一下「Esc」→輸入「:1,$s/123/456/g」→再按「Enter」即可作搜尋並取代的動作!
此範例是將文字123更換成文字456,並且將此文件裡的所有符合的皆取代。
1,$ 指的就是從頭至尾。

參考資料:
dreamtails 筆記
https://dreamtails.pixnet.net/blog/post/27863994


25. Red Hat Enterprise Linux Server 帳號問題

SSH 帳號超過 5 個後,好像會有些問題 = = 


26. 由 windows 編緝 script 放到 linux 中,常會發生一個問題 ^M 多出斷行符號,這時可以使用以下方式處理

cat -v [script] <= 列出詳細內容,這個方式會出現斷行符號
dos2unix [script] <= 這個指令會將 dos 檔案轉為 unix 格式,這時 ^M 就會消失

註1:需安裝 dos2unix 套件
註2:bash -x [script] 這個方式可以列出詳細的 script 執行情形
註3:放到 linux 中的幾種方式都可能發生,複製 貼上、Filezilla上傳等等…

參考資料:
james 大指導


27. Server World

這個網站寫了很多關於 Server 的技術文件,原文是日文

https://www.server-world.info/en/ 


28. VirusTotal

一個擁有全部掃毒引擎的網站,可以手動上傳 URL、file 及 search,不錯的方式

官方網站
https://www.virustotal.com/gui/home/upload 


29. Linux 系統路硬碟使用量

 

參考資料:
GTW -- Linux 檢查硬碟使用量 df 指令教學與指令稿範例
https://blog.gtwang.org/linux/linux-df-command-check-disk-space-usage-tutorial-script-example/ 


30. Linux 找出最耗費 CPU 與記憶體資源的程式

 

參考資料:
GTW -- Linux 用 ps 與 top 指令找出最耗費 CPU 與記憶體資源的程式
https://blog.gtwang.org/linux/ps-top-find-processes-by-cpu-memory-usage/ 


31. Message Queue 簡介(以 RabbitMQ 為例)

 

參考資料:
小信豬大的文章 -- Message Queue 簡介(以 RabbitMQ 為例)
https://godleon.github.io/blog/ChatOps/message-queue-concepts/

GTW -- 以 RabbitMQ 實作工作佇列(Work Queues)(Python 版本)
https://blog.gtwang.org/programming/rabbitmq-work-queues-in-python/ 


32. CentOS 不再支援啦!

這樣啊!看看 CentOS stream 吧!

參考資料:
iThome -- 紅帽棄守CentOS Linux,將於明年底終止對CentOS Linux 8的支援
https://www.ithome.com.tw/news/141582

官方文件 -- CentOS stream
https://www.centos.org/centos-stream/
https://wiki.centos.org/zh-tw/Manuals/ReleaseNotes/CentOSStream 


33. PAM 模組

鳥哥有教呢!真是沒好好學,學會 PAM 對於帳號密碼的管理,會強化很多

required <= 必需執行,但不中斷接下來的流程,並在完成後留下紀錄
requisite
<= 必需執行,不通過則中斷接下來的流程。所以要強制執行的設定必需寫在這個後面

參考資料:
鳥哥
http://linux.vbird.org/linux_basic/0410accountmanager/0410accountmanager-fc4.php#usershell  


34. 黑箱測試、源碼檢測

外部弱點掃瞄就是最好的黑箱測試

參考資料:
wiki -- 黑箱測試
https://zh.wikipedia.org/wiki/%E9%BB%91%E7%9B%92%E6%B5%8B%E8%AF%95

iT邦幫忙 iThelp 大文章 -- 什麼是網頁應用程式源碼檢測
https://ithelp.ithome.com.tw/articles/10000009 


35. MobaXterm 開啟 SSH agent forwarding 方式

MobaXterm 是一個不錯的 SSH 外殼,他包下了大多數常用的 remote controller 是個實用的工具,不過, towns 還是習慣使用 putty

參考資料:
MkDocs 文章 -- SSH agent forwarding with MobaXterm on Windows
http://docs.gcc.rug.nl/hyperchicken/ssh-agent-forwarding-mobaxterm/ 


36. nessus 官方教學

nessuscli -v <== 版本查詢

https://docs.tenable.com/nessus/Content/CommandLineOperations.htm 


37. 關於 docker 中 gitlab 無法啟動的問題

 

參考資料:
enough -- Loïc Dachary 大回應
https://lab.enough.community/main/infrastructure/-/issues/29


38. DEK 與 KEK

DEK(Data_Encryption_Key)=> 資料加密用的金鑰
KEK(Key_Encryption_Key)=> 保護DEK金錀的金鑰

兩者的關係為 程式讀取 KEK 解密 DEK,再讀取 DEK 解密檔案。加密時也是相同的,其目的為保護 DEK
而 PCI 要求 KEK 及 DEK 這兩把金錀不能存放在同一個位置(資料匣),如不同的資料匣或不同的 host 中
所以程式在加解密時,必需能讀取兩把金鑰

如果使用 HSM 取代 KEK 方式,DEK 是保存在 HSM 中並使用 HSM 的主金鑰(Master Key;也有稱做主基碼,這個其實就等於是 KEK)做 DEK 加密,所以需要保護的就是這個主金鑰,一般來說多半是將主金鑰匯出並放置於特定的媒體(如晶片卡、隨身碟等…)並將密密碼分持保管

名詞說明
Triple-DES(3DES;Triple Data Encryption Algorithm;三重資料加密演算法),3DES已經逐漸被更安全的AES代替

資料來源:mason 口述

其他資料:
財金資訊 -- 陳則黎先生文件
https://docsplayer.com/74831701-%E9%9B%BB%E5%AD%90%E9%8A%80%E8%A1%8C%E7%9B%B8%E9%97%9C%E5%AE%89%E5%85%A8%E6%8A%80%E8%A1%93.html

wiki -- Triple-DES
https://zh.wikipedia.org/wiki/3DES 


39. 關於 sudo 設定方式

1. 將使用者加入 sudo 群組
adduser towns sudo <== 將 towns 加入 sudo 群組
deluser towns sudo <== 將 towns 移出 sudo 群組

這個方式最不好的地方就是使用者 sudo 權限過大,最好的方式是用 2 的方法

2. 修改 /etc/sudoers
這個方式可以參考 Linux 隨手記2 中 sudo 資訊

3. 新增 /etc/sudoers.d/[帳號]
這個方式是跟 2 相同的,只是寫到 /etc/sudoers.d/ 中,這是一個單純化設定檔的方式,現在 towns 比較推這個方式

參考資料:
阿舍大的隨手記
http://www.arthurtoday.com/2015/01/how-to-add-a-user-as-sudoer-using-the-command-line-in-ubuntu.html  

這個不知道是哪位大大寫的 -- Ubuntu Linux 設定 sudo 使用者、群組教學與範例
https://officeguide.cc/ubuntu-linux-sudo-sudoer-user-group-configuration-tutorial-examples/

這個到不是只有 sudo 部分的建議,現在 Linux 系統有很多的套件客製設定建議,都是放在 *.d 中,如apache、pam、cron等…,下面只是 towns 的一個紀錄

ubnutu
/etc/sudoers.d/abcd
abcd   ALL=(ALL:ALL) ALL
Defaults:abcd !requiretty

CentOS
/etc/sudoers.d/abcd
abcd   ALL=(ALL) ALL
Defaults:abcd !requiretty


40. SSH 密碼 + google-authentication 雙因素認證

為了安全性,多數都開始要使用多因素認證,而這個方式是很多人使用的方式了

0. 添加CentOS 7的epel

1. 先安裝相依性套件
# yum install gcc make pam-devel libpng-devel libtool wget git –y
# yum groupinstall "Development Tools" -y
# yum install qrencode -y  Google用這個套件產生二維條碼登入(這個也不需要裝,有 qrencode-libs 就可以了)
註1:towns 沒裝這麼多套件(pam-devel、libpng-devel、libtool、wget、git 都沒裝)
註2:Oracle Linux 預設沒有 qrencode 套件

2. 下載並安裝 google 驗證器 (建議直接安裝這個就好)
# yum install google-authenticator -y

3. 設定 ssh 連線資訊
#vim /etc/ssh/sshd_config
#將下方這行修改為yes(這個選項 towns 沒有設定,依舊可以使用,大家也可以試試,經過測試,是可以的)
ChallengeResponseAuthentication yes
#加入驗證模式
#vim /etc/ssh/sshd_config
UsePAM yes
重啟sshd服務
#systemctl restart sshd

4. 設定pam
開始設定/etc/pam.d/sshd
#vim /etc/pam.d/sshd
#添加下面的設定 ( towns依IT001大大選擇使用第二個)
auth substack password-auth
auth required pam_google_authenticator.so
OR
auth substack password-auth
auth required pam_google_authenticator.so nullok

5. 啟動 google-authentication **需要網路**
# google-authentication
操作部分基本上都先輸入[ y ]
可以看看說明,這些說明是在設定動態密碼的一些規則
之後就會顯示QR code要用來驗證,或者輸入下方Verification code來驗證。
Emergency scratch code是沒有手機時的緊急登入代碼。
之後這邊的檔案會存在家目錄下的.google_authenticator之中。
!!使用者手機安裝Google Authenticator APP
這邊需要使用者用手機掃描QR code加入認證。
之後一路按[ y ]就好。

6. 手機安裝 google authenticator 後利用手機綁定

補充:
1.啟用時,也可以帶參數自動建立完成驗證碼
# google-authenticator -t -d -f -r 3 -R 30 -W

2.這邊是在sshd當中添加,當然也可以考慮在su當中添加。
這個時候只要將設定加到/etc/pam.d/su就可以了。

3.那一位使用者要使用 google-authenticator,需要兩次
第一次會提供URL由線上產生
第二次會直接產生於 ssh 上

參考資料:
IT001大大的文章
https://it001.pixnet.net/blog/post/356150624-it%E4%BA%8B%E4%BB%B6%E7%B0%BF--centos-7-ssh-%E5%85%A9%E6%AD%A5%E9%A9%9F%E9%A9%97%E8%AD%89-google-authenticat 


41. 測試 TLS 回應

這個方式主要是要確認對方網站是否有支援 TLS 特定版本,可以透過以下指令測試,如果要測試自己,就打自己的網址吧!

curl https://www.google.com.tw --tlsv1.2 -vvv
openssl s_client -connect www.google.com.tw:443 -tls1_2

參考資料:
ryan 大口述


42. audit 功能

不知道何時開始 red hat 系列出現了 audit 這個功能

參考資料:
Johnson峰 大的文章
https://johnson560.pixnet.net/blog/post/316189467-linux-%E7%9A%84-audit-%E6%9C%8D%E5%8B%99 


43. curl 指令

curl -v -k -XPOST https://a.b.c --tlsv1.2 


44. 網頁版變更 LDAP 密碼工具

 

註1:AD不可勾選“使用者在下次登入時變更密碼”(可能有解法,不過目前還沒試出來)
註2:如果有開啟密碼最短使用期限,也會造成密碼無法變更的情形

參考資料:
ian 口述

jirutka 大大的程式
https://github.com/jirutka/ldap-passwd-webui 


45. 使用 kill -9 仍無法殺掉的程序

kill -9發送SIGKILL信號將其終止,但是以下兩種情況無反應:
a、該程序處於”Zombie”狀態(使用ps命令返回defunct的進程)。此時程序已經釋放所有資源,但還未得到其父程序的確認。“zombie”程序要等到下次重啟時才會消失,但它的存在不會影響系統性能。
b、該程序處於“kernel mode”(核心模式)且在等待不可獲得的資源。處於核心模式的進程忽略所有信號處理,因此對於這些一直處於核心模式的程序只能通過重啟系統實現。程序在AIX 中會處於兩種狀態,即使用者模式和核心模式。只有處於使用者模式的進程才可以用“kill”命令將其終止。

towns 應該是遇到了第一個問題

內容為在風中的意志的資料並做了少量文字修改,請風大多多包函,謝謝

參考資料:
在風中的意志大大的blog
https://blog.csdn.net/u010416101/article/details/72331799


46. 追蹤程序小技巧

ps -ef [程序號] <= 左邊數字為 PID、右邊數字為 PPID,一層一層追蹤,就可以看出該程式是由誰開啟的

資料來源:
ryan 大口述 


47. Netcat 網管工具

這個套件可以測試 TCP、UDP 外,還可以開啟連接埠監聽,是個相當實用的工具

參考資料:
GTW -- Netcat(Linux nc 指令)網路管理者工具實用範例
https://blog.gtwang.org/linux/linux-utility-netcat-examples/


48. NFS 的 soft 及 hard 模式差別

soft 模式
當用戶端掛載的時候採用soft模式,我們可以配置timeo和retry參數,配置超時時間,伺服器端出現異常,用戶端也會向伺服器端發請求,當超過我們配置的時間,則會返回錯誤,不會一直阻塞。

hard 模式
當用戶端掛載的時候採用hard模式,伺服器端出現異常,則用戶端會一直發請求,直到伺服器正常。

預設為 hard 模式

參考資料:
dmfrm 大的文章 -- NFS的soft和hard模式
https://blog.csdn.net/u010889616/article/details/53705503 


49. Nessus rpm online 更新


註:更新 nessus 套件後,必需 stop 再 start 服務才會起來(8834),restart 不行呢!不然,就是 reboot 系統

參考資料:
官方討論 -- Casey Robertson 大回應
https://community.tenable.com/s/question/0D53a00007c2b95CAA/downloading-with-wget 


50. curl 帶憑證

curl https://ab.com.tw/aaa/bbb.hhh --cert /a/aaa.crt

 


51. cron.d 中的檔案權限

如果在 syslog 中看到以下錯誤,表示 cronjob 並沒有執行,需將 cron.d 中的檔案權限必需為 644 才能正常執行

註:(*system*timesync) INSECURE MODE (group/other writable) (/etc/cron.d/timesync)

 


52. 查詢本機外部 IP

linux 下,可以下這一段語法試試
curl ifconfig.io

資料來源:rudy 口述


53. ubuntu 22.04 安裝嘸蝦米

最近因為舊筆電使用 win 10 效能非常差,而且溫度又高,towns 覺得這個可能與 win 10 更新後有關,試著降版安裝,結果還是有相同問題,最後,towns 試著變更為 ubuntu 22.04,再來試試看了 ^^。沒想到 ubuntu 進步這麼多了,居然有嘸蝦米的套件,變的非常好安裝,真是另人意外。

參考資料:
iT邦幫忙 -- 不明大的文章
https://ithelp.ithome.com.tw/articles/10257501  


54. ubuntu 22.04 伺服器最小版沒有 ping 指令,需自行安裝 iputils-ping 套件

參考資料:
Korbin Brown 大文章
https://linuxconfig.org/ping-command-not-found-on-ubuntu-22-04-jammy-jellyfish-linux 


55. SoftHSM

 

參考資料:
程式人生
https://www.796t.com/post/YmtiOHU=.html

官網
https://www.opendnssec.org/softhsm/


56. 兩張網卡綁成一張 -- Linux Bonding

 

參考資料:
henry 大大的文章
https://blog.xuite.net/henry690621/blog/32959369-Linux+Bonding%E7%B6%B2%E5%8D%A1%E7%B6%81%E5%AE%9A%E5%AF%A6%E4%BD%9C# 


57. 這些在指令後面是做什麼的? |、||、&、&&

& 如果在指令後面加上 & 符別, 即表示指令在背景執行, 例如 my-script.sh &
&& 用 “&&” 分開兩個指令, 即第一道指令執行成功後, 才會執行第二道指令, 例如 make && make install
| 這是管線的符號, 即是將第一道指令的輸出, 作為第二道指令的輸入, 例如 ls | grep filename
|| 表示第一道指令執行失敗後, 才會執行第二道指令, 例如 cat filename || echo “fail”
Sam大不好意思,照抄了

參考資料:
Sam Tang大的說明
https://www.ltsplus.com/linux/linux-and-andand


58. 另一套 ssh 連接工具 xshell

在透過網路設備(如A10、switch等…)連接其他網路設備時,有時會因為安全性設定造成連接錯誤(如 no matching mac found: client hmac-sha1 server hmac-sha2-512)而無法連入,這時可以試試這一套工具,也許,可以自動選擇能使用的加密協定

參考資料:
steve 大口述

官網:
https://www.netsarang.com/en/xshell/ 


59. curl 指令的 sample

有很多 curl 的 sample,蠻實用的

參考資料:這個應該不是一個大大的資料,不過,謝謝啦!
https://reqbin.com/req/c-70cqyayb/curl-timeout 


60. node.js 與 python

 

參考資料:
這個不知道是那個大大寫的 -- node.js 與 python 比較
http://www.tastones.com/zh-tw/tutorial/nodejs/nodejs-vs-python/

circleuniv 大大文章 -- node.js 建立本機 web server
https://ithelp.ithome.com.tw/articles/10185302

Chwang 大大文章 -- python 建立本機 web server
https://chwang12341.medium.com/coding%E8%B5%B7%E4%BE%86-python-%E4%B8%80%E8%A1%8C%E6%8C%87%E4%BB%A4%E5%B0%B1%E8%83%BD%E8%BC%95%E9%AC%86%E5%BB%BA%E7%AB%8B%E7%B6%B2%E9%A0%81%E4%BC%BA%E6%9C%8D%E5%99%A8-simplehttpserver%E5%A5%97%E4%BB%B6-http-server%E4%BD%BF%E7%94%A8%E6%95%99%E5%AD%B8-34c30b81c26

微軟說明 -- node.js 安裝
https://learn.microsoft.com/zh-tw/windows/dev-environment/javascript/nodejs-on-windows 


61. sh [script] 及 ./[script] 的差別

towns 有時會看到有同事使用 $sh test.sh,也會看到有人使用 ./test.sh,但他有什麼差別?今天 towns 才注意到這個差別,主要是差在該 script 檔案,是否有執行權限(x 權限),當該檔案有 x 時,可以使用 ./test.sh 這個方式,如果沒有但要執行就得使用 sh test.sh 方式執行


62. 無法使用 GCP

看來 towns 是無緣使用 GCP 了,因為 google 將 towns 的帳戶視為有問題的帳戶,所以不讓 towns 開啟帳單帳戶,這個應該是早期使用 google Adsense 的部落格廣告造成,看來不是重新申請一個帳號試試,不然就是不能使用了,那就再看看了。


63. history 管理

清除單行:history -d [line number]
全部清除:history -c

註:清除單行後,排序會自動上移

參考資料:
steven morris
https://opensource.com/article/18/6/history-command 


64. sonarqube open 的原碼檢測工具

Sonarqub 現在的安裝非常簡單,只需要依照 Ganesan C 大大文章一步步完成,就可以掃描本地端的檔案了

docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

sonar-scanner.bat -D"sonar.projectKey=test-key" -D"sonar.sources=." -D"sonar.host.url=http://localhost:9000" -D"sonar.login=<sonar-token-here>"

sonar-scanner.bat -D"sonar.projectKey=test-key" -D"sonar.sources=<file-or-folder-path-here>" -D"sonar.host.url=http://localhost:9000" -D"sonar.login=<sonar-token-here>"

參考資料:
office 指南
https://officeguide.cc/sonarqube-code-quality-security-review-tool-tutorial-examples/

本地掃描安裝教學:
Ganesan C 大大文章
https://www.c-sharpcorner.com/article/how-to-setup-the-sonarqube-on-local-machine/

The Code Switch 大大影片
https://www.youtube.com/watch?v=lOY8oWQxG-E

Bhargav Bachina 大大文章 -- 建置 java 掃瞄環境
https://medium.com/bb-tutorials-and-thoughts/setting-up-sonarqube-on-your-local-machine-for-java-projects-b8198b3103fb

Knoldus 大大文章 -- 建置 java 掃瞄環境
https://medium.com/knoldus/how-to-integrate-your-maven-project-with-sonarqube-79f7368f8c7a

ubunto 安裝 open-jdk
https://linuxize.com/post/install-java-on-ubuntu-18-04/


留言

這個網誌中的熱門文章

zimbra 安裝、管理、設定

Fortigate 100D -- 管理、設定

IT 隨手記6