發表文章

目前顯示的是 3月, 2024的文章

關掉 RPi 的密碼登入功能

$ cd /etc/ssh $ nano sshd_config 加入以下三行 PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no 存檔 重新啟動 ssh 服務 $  sudo systemctl restart ssh 最後你可以在 terminal 開另外一個 tab 來驗證是否成功: $  ssh pi@your-ip -o PubKeyAuthentication=no pi@your-ip: Permission denied (publickey).

RPi 作業系統的 ntp service 相關

查詢系統的自動同步時間服務 $ sudo systemctl status ntp.service  # 是否正常執行中 $ sudo systemctl stop ntp.service  # 停止 $ sudo systemctl start ntp.service  # 執行 $ sudo systemctl restart ntp.service  # 重新執行 $ sudo systemctl disable ntp.service  # 停用 $ sudo systemctl enable ntp.service  # 啟用 查詢 ntp 設定檔 $ cat /etc/ntp.conf # 使用 chronyd 的話 $ cat /etc/chrony/chrony.conf # 或是 $ less /etc/ntp.conf  # note: press q to exit 也可以使用以下命令直接查詢正在使用的 NTP 伺服器。這會向 NTP 伺服器發送查詢並顯示響應 $ ntpd -pdn # 使用 chronyd 的話 $ chronyc sources 修改 ntp 設定檔 $ sudo nano /etc/ntp.conf 加進多個 pool pool 1.tw.pool.ntp.org iburst pool 2.pool.ntp.org  iburst pool 0.tw.pool.ntp.org iburst pool 0.asia.pool.ntp.org iburst ntp service 路徑位置 $ sudo nano /lib/systemd/system/ntp.service 標案內容 [Unit] Description=Network Time Service Documentation=man:ntpd(8) After=network.target Conflicts=systemd-timesyncd.service [Service] Type=forking # Debian uses a shell wrapper to process /etc/default/ntp # and select DHCP-provided NTP servers if available ExecStart=/usr/li

如何設定crontab工作排程器 RPi

以 ntp 系統自動更新時間為相關例子 確認 crontab 服務正常 $ sudo systemctl status  crontab.service  # 是否正常執行中 $ sudo systemctl stop    crontab.service  # 停止 $ sudo systemctl start   crontab.service  # 執行 $ sudo systemctl restart crontab.service  # 重新執行 $ sudo systemctl disable crontab.service  # 停用 $ sudo systemctl enable  crontab.service  # 啟用 可以新增檔案放在 /etc/cron.d/ ,系統就會自動載入   $ sudo nano /etc/cron.d/auto_ntpdate 內容示意 */1 * * * * /bin/sh /home/pi/exec/whatevershell.sh > /dev/null 5 * * * *  root (/usr/sbin/ntpdate 118.163.81.63 )  &> /dev/null 10 * * * * root (/usr/sbin/ntpdate 162.159.200.1 )  &> /dev/null 15 * * * * root (/usr/sbin/ntpdate 17.253.116.253 ) &> /dev/null 20 * * * * root (/usr/sbin/ntpdate 103.147.22.149 ) &> /dev/null 25 * * * * root (/usr/sbin/ntpdate 211.22.103.157 ) &> /dev/null 30 * * * * root (/usr/sbin/ntpdate 140.112.2.188 )  &> /d

列出有在監聽的 port 指令

看有開的 port (listening ports) $ sudo netstat -tulpn $ sudo ss -tulpn $ sudo lsof -i -P -n | grep LISTEN
1. 在要連線的 client 端建立公鑰和私鑰 ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa.myskydevice -C "your_email@example.com" 2. 在 client 端 將公鑰添加到 server 端的授權鍵列表中:將 id_ rsa.myskydevice.pub 文件中的內容添加到目標用戶的 ~/.ssh/authorized_keys 文件中。如果該文件不存在,請創建它。 cat ~/.ssh/id_rsa.myskydevice.pub | ssh -i id_rsa.skydevice root@skydevice.local 'cat >> ~/.ssh/authorized_keys' 創建 authorized_keys touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys 3. 在 server 端設置文件和文件夾權限:請確保 ~/.ssh 文件夾的權限為 700,並且 authorized_keys 文件的權限為 600。 chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys 4. 在 server 端啟用 SSH 登入:確保您的 SSH 服務已啟用。如果您使用的是 Raspberry Pi,SSH 通常已經預先安裝並啟用。如果不確定,您可以通過運行以下命令來檢查: sudo systemctl status ssh 如果 SSH 服務未運行,您可以使用以下命令啟動它: sudo systemctl start ssh 5. 使用 nano 或 vi 查看和編輯 authorized_keys 文件:在您添加公鑰後,建議使用 nano 或 vi 來查看和編輯 ~/.ssh/authorized_keys 文件,以確保其中沒有任何亂碼或格式問題。 使用 nano 查看: nano ~/.ssh/authorized_keys 或者使用 vi 查看: vi ~/.ssh/authorized_keys

MacOS 讀取記憶卡 image 存到硬碟

圖片
開啟 Disk Utility app 在 External > Generic STORAGE DEVICE Media 按右鍵選 【Image from "…"】 檔名方便複製: 【給什麼單位用-型號-在什麼平台上-版本】 Format 選: 【DVD/CD master】 【Save】 Example: 會存成 .cdr 檔,改成 .iso 即可 注意,~/.ssh/authorized_keys 會被改寫 done 從備份的 image 檔燒回 SD Card 後,~/.ssh/authorized_keys 檔要先做清空內容的動作,裡面有莫名的亂碼。

RPi 讓作業系統預設的螢幕輸出不要顯示到螢幕上

可以直接記憶卡插上電腦,進入到 boot 資料夾 關掉 HDMI output display 改 /boot/config.txt 加兩行參數 disable_splash=1 hdmi_blanking=2 改 /boot/cmdline.txt 把 console=tty1 改成 console=tty 3   在 rootwait 後加上 quiet splash loglevel=3 logo.nologo vt.global_cursor_default=0  也可以加這三個參數,未知作用,可以試試: disable_overscan=1 dwc_otg.lpm_enable=0 plymouth.ignore-serial-consoles 反之,可顯示 output

RPi 新增使用者帳號

RPi 新增使用者帳號,記得權限先都不給 $ sudo useradd <username> $ sudo grep <username> /etc/passwd /etc/shadow /etc/group $ sudo passwd <username> # 改密碼 $ sudo cp -a /etc/skel /home/ <username> $ sudo grep <username> /etc/passwd /etc/shadow /etc/group

RPi 應設的權限

自己的 home 目錄,以帳號 pi 來說,以下幾種 $ chmod 750 /home/pi # 只有 pi 有全部權限rwx、跟群組可rx該資料夾 $ chmod 700 /home/pi # 嚴格,群組跟其它人都不能進該資料夾(eg. cd 或 ls) $ chmod 751 /home/pi # 可以讓其它人進該資料夾,比如說 nginx 或 www-data (不在群組的話),但看不到這一層有什麼檔案。不過知道有哪些檔案或資料夾,並且權限符合的話,可以直接 cd 那些資料夾或是 cat nano vi 檔案等等的指令。 SSH的權限 $ chmod 600 ~/.ssh/id_rsa $ chmod 644 ~/.ssh/id_rsa.pub $ chmod 600 ~/.ssh/known_hosts $ chmod 600 ~/.ssh/authorized_keys $ chmod 700 ~/.ssh 如果有使用到SSL憑證的話,不應該變更這兩個檔 $ sudo chmod 664 server.key $ sudo chmod 664 server.crt