ubuntu24 换源 ssh配置

备份原源配置

sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak

编辑源文件(DEB822 格式)

sudo nano /etc/apt/sources.list.d/ubuntu.sources

替换内容(以阿里云为例)

Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

其他可选源:

  • 清华:https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
  • 中科大:https://mirrors.ustc.edu.cn/ubuntu/

更新

sudo apt update

安装 SSH 笔记

1. 安装

sudo apt update
sudo apt install openssh-server -y

2. 启动并设置开机自启

sudo systemctl enable --now ssh

3. 防火墙放行

sudo ufw allow ssh
sudo ufw reload

4. 安全配置(编辑 /etc/ssh/sshd_config

建议修改:

  • Port 2222(改默认端口)
  • PermitRootLogin no
  • PasswordAuthentication no(先用密钥登录成功后改)
  • PubkeyAuthentication yes

修改后重启:

sudo systemctl restart ssh

5. 密钥登录(可选)

客户端生成密钥:ssh-keygen -t ed25519
上传公钥:ssh-copy-id user@ip(默认端口)或 ssh-copy-id -p 端口 user@ip

posted @ 2026-08-26 15:02  Hey,Coder!  阅读(2)  评论(0)    收藏  举报