WordPress 筆記

How Smart Tools Are Shaping the Future of Creative Work

Eric Chuang
2024-09-21

使用 Webinoly 建立網站時,會自動建立 www-data:www-data 作為網站資料夾的擁有者。然而,當你登入伺服器進行操作時,通常是以個人使用者帳戶進行登入,會產生檔案權限的問題。此時,如果直接使用 sudo,在下載檔案以後,會預設將檔案所有權設為 root:root,需要另外再把所有權指派回去給 www-data:www-data,這對於使用 GitHub 來進行版本控制來說有點麻煩。

今天這篇文章將針對 Webinoly + GitHub 環境的設定做快速的說明。

切換至 www-data 的權限

結論來說,你需要下面這個指令,將操作權限切換為 www-data。

sudo -u www-data -s

因為 www-data 並不是一個完整的使用者帳號,所以是無法使用 sudo su www-data 進行切換的。

將 Webinoly 與 GitHub 專案連結的方法

因為進行公司客戶的專案時,建立的大多是私有儲存庫 (Private Repository),必須驗證身份後才能與儲存庫進行連結。下面將針對建立金鑰、與 GitHub 連結再做補充。

建立 SSH 金鑰

為了從 GitHub 提取 (Pull) 更新,需要在主機上建立金鑰。

ssh-keygen -t ed25519 -C "[email protected]"

此時 SSH 金鑰會建立在 /var/www/.ssh/ 底下。

接著要將公開金鑰 (Public Key) 新增至 GitHub 當中。

複製 SSH 公開金鑰

cat ~/.ssh/id_ed25519.pub

將顯示出來的公開金鑰 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI… [email protected] 複製。

將金鑰新增至 GitHub

  • 前往 GitHub 的 Settings > SSH and GPG Keys。
  • 點擊 New SSH Key。
  • 輸入識別用的金鑰名稱,並將剛才複製的公開金鑰貼上。
  • 點擊 Add SSH Key 完成新增。

回到主機測試連結

回到伺服器,繼續以 www-data 的身份,測試 GitHub 連結。

成功連線後,終端機會顯示你的 GitHub 帳號名稱,如下圖所示:

開始 Git 的操作

完成上述步驟後,你就可以在網站目錄中以 www-data 身份,正常執行 Git 的相關指令,進行自製外掛或佈景主題的更新了。

Sign up for our newsletter

Subscribe to our newsletter to receive the latest updates, expert insights, and practical tips directly in your inbox. Stay informed with content designed to help you grow.

+480.000 happy customers

Gain more with expert solutions

Unlock the full potential of your business with our expert solutions. Our team provides tailored strategies, professional guidance, and actionable insights to help you achieve better results.

  • Eric Chuang
  • •
  • 2025-01-23
如何同時使用 Webinoly 與 Cloudflare 保護網站安全

在社群夥伴勇哥的文章〈Webinoly 最新版快速安裝〉中,提到使用 Webinoly 來建立 WordPre […]

主機