希曼日记

Ubuntu

本页目录 9
  1. 解决machine-id 冲突
  2. 增加超时时间
  3. 修改密码
  4. 允许Root用户登录
  5. 使用国内源
  6. 设置密钥登录
  7. 静态IP
  8. 克隆出现的UUID相同问题
  9. clash代理

解决machine-id 冲突

  1. 清除现有的旧配置:
Shell
sudo rm -f /etc/machine-id
sudo rm -f /var/lib/dbus/machine-id

其中,/var/lib/dbus/machine-id 通常是到 /etc/machine-id 的一个软链接,但有些发行版会作为独立文件存在,因此建议都删除

  1. 生成新 ID:使用 systemd-machine-id-setup 工具重新生成一个新的唯一标识:
Shell
sudo systemd-machine-id-setup
cat /etc/machine-id

增加超时时间

客户机: ~/.ssh/config

Text
Host *
ServerAliveInterval 60
ServerAliveCountMax 3

服务器:

Bash
cat >> /etc/ssh/sshd_config <<EOF
ClientAliveInterval 60
ClientAliveCountMax 3
EOF
sudo systemctl restart ssh

修改密码

Text
sudo passwd root

允许Root用户登录

Text
sudo sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo systemctl restart ssh

使用国内源

Bash
sudo sed -i 's/ports.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update && sudo apt upgrade -y

设置密钥登录

Bash
sudo sed -i 's/#PubkeyAuthentication no/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
sudo sed -i 's/PubkeyAuthentication no/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
cat /etc/ssh/sshd_config | grep PubkeyAuthentication
systemctl restart ssh
systemctl restart sshd

静态IP

  1. 将虚拟机软件设置为桥接
  2. 查看mac的路由器的信息
  3. 在/etc/netplan/00-installer-config.yaml或者50-cloud-init.yaml或类似名称
Shell
cp /etc/netplan/00-installer-config.yaml{,.back}
cat > /etc/netplan/00-installer-config.yaml <<EOF
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s5:
dhcp4: false
dhcp6: false
addresses:
- 192.168.3.160/24
nameservers:
addresses:
- 192.168.3.1
- 114.114.114.114
routes:
- to: default
via: 192.168.3.1
version: 2
EOF
# Netplan配置文件不应该对其他用户开放访问权限 过于开放的权限,这可能会导致安全风险
sudo chmod 600 /etc/netplan/00-installer-config.yaml
# 生成和应用更改
sudo netplan generate
sudo netplan apply

克隆出现的UUID相同问题

kubernetes以UUID区分集群机器标识, 相同的UUID的虚拟机/机器不能加入集群

  1. 参考CSDN
  2. 列出虚拟机:
Shell
prlctl list -a
  1. 把重复的UUID的虚拟机的UUID取消注册
Shell
prlctl unregister node2
  1. 重新注册生成新的UUID. 在mac主机上的终端执行以下命令: 把/Users/lisa/Public/Linux/Ubuntu/master/master1.pvm/替换为你要更改的UUID虚拟机的pvm路径
Shell
prlctl register --regenerate-src-uuid ~/linux/node2.pvm

clash代理

设置代理

HTTP(S)

别名 linux:

Bash
USER_PATH="/root"
SHELL_FILE="${USER_PATH}/.bashrc"
MAC_IP="192.168.3.220"
sudo cat >> $SHELL_FILE <<EOF
alias proxy="export http_proxy='http://$MAC_IP:7890';export https_proxy='http://$MAC_IP:7890'"
alias unproxy="unset http_proxy; unset https_proxy; unset all_proxy; echo 'Unset proxy successfully'"
EOF
source $SHELL_FILE
cat $SHELL_FILE

mac:

Shell
USER_PATH="/root"
SHELL_FILE="${USER_PATH}/.bashrc"
#export SHELL_FILE="~/.zshrc"
#MAC_IP="192.168.3.220"
MAC_IP="192.168.3.220"
sudo cat >> $SHELL_FILE <<EOF
alias proxy="export http_proxy='$MAC_IP:7890';export https_proxy='$MAC_IP:7890'"
alias unproxy="unset http_proxy; unset https_proxy; unset all_proxy; echo 'Unset proxy successfully'"
EOF
source $SHELL_FILE
cat $SHELL_FILE

Clash的Tun模式 与 WireGuard冲突 一份参考: https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml 打开clash的配置文件config.yaml, 添加:

YAML
...
interface-name: en0
...