ubuntu24系统怎么用密钥登录服务器
美国、香港服务器
ubuntu24系统怎么用密钥登录服务器
03-17 来源:
一、本地电脑先生成密钥(Windows / Mac 都行)
Windows(用 CMD / PowerShell)
bash


运行
ssh-keygen -t
ed25519
一路回车,不用设密码。
生成位置:
plaintext
C:\Users\你的用户名\.ssh\
里面有两个文件:
• id_ed25519 私钥(自己留着)
• id_ed25519.pub 公钥(传到服务器)
二、把公钥传到 Ubuntu 24 服务器
1. 登录服务器,创建 .ssh 目录
bash
运行
mkdir -p
~/.ssh
chmod 700
~/.ssh
2. 编辑 authorized_keys
bash
运行
nano
~/.ssh/authorized_keys
把你本地 id_ed25519.pub 里的一长串内容粘贴进去。
3. 设置权限(非常重要,不然密钥登不上)
bash
运行
chmod 600
~/.ssh/authorized_keys
三、配置 SSH 启用密钥登录
bash
运行
nano
/etc/ssh/sshd_config
确保这几项是这样:
ini
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
PermitRootLogin prohibit-password
重启 SSH 生效
bash
运行
systemctl restart sshd
四、现在测试登录
你本地直接:
bash
运行
ssh
用户名@服务器IP

不需要密码,直接登录成功。

五、安全提醒
• 关闭密码登录后,千万不要弄丢私钥
• 密钥文件权限必须是 600,目录 700
• Ubuntu 24.04 默认用 openssh-server,这套配置完全通用
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快