lxc/lxd container 建立與管理及佈署基本指令 – part. 1

首先登入 lxc

lxc exec lxc00 bash

或是

lxc shell lxc00

安裝及設定必備的環境

sudo cp /etc/apt/sources.list sources.list.default
sudo sed -i 's/archive.ubuntu.com/free.nchc.org.tw/g' /etc/apt/sources.list
sudo apt update && sudo apt dist-upgrade
sudo apt install bash-completion net-tools command-not-found byobu openssh-server curl man-db software-properties-common byobu dnsutils ppa-purge iotop sysstat sshfs virt-what htop git unzip rsync apt-transport-https

必備環境安裝說明:

  • 變更 apt server 到離你最近或是頻寬最佳的,可以參考這篇 挑選最佳的 Ubuntu apt mirror
  • 更新 apt db
  • 安裝基本環境軟體
    • bash-completion net-tools command-not-found byobu openssh-server curl man-db software-properties-common byobu dnsutils ppa-purge iotop sysstat sshfs virt-what

設定 auto completion (ubuntu 這個帳號也要一次)

echo "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
source /etc/profile.d/bash_completion.sh
su -l ubuntu && echo "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
source /etc/profile.d/bash_completion.sh

修改密碼

sudo passwd
sudo passwd ubuntu

產生金鑰不用密碼登入

ssh-keygen -t ed25519 -f ~/.ssh/192.168.1.2 -C ubuntu@192.168.1.2
ssh-copy-id -p 22 -i ~/.ssh/192.168.1.2.pub ubuntu@192.168.1.2
ssh ubuntu@192.168.1.2

修改 sshd 設定

sudo vim /etc/ssh/sshd_config
PasswordAuthentication no
PubkeyAuthentication yes

發表迴響

回到頂端