原创文章,转载请注明出处
https://qiedd.com/

适用于大多数主流使用 Systemd 的 Linux 发行版

安装ssh服务
# Debian/Ubuntu
sudo apt update -y && sudo apt install openssh-server -y

# Centos
sudo yum update -y && sudo yum install openssh-server -y

# ArchLinux
sudo pacman -Sy openssh --needed --noconfirm
生成和配置私钥
# 生成私钥,一路回车即可
ssh-keygen -t rsa

# 配置私钥
cd ~/.ssh
cp id_rsa.pub authorized_keys

# 权限必须设置为700,否则无法使用
chmod 700 authorized_keys

# 修改配置文件
vim /etc/ssh/sshd_config

可以参考 Arch wiki
https://wiki.archlinux.org/title/OpenSSH#Force_public_key_authentication

然后将 /root/.ssh 中的 id_rsa 导出到本地,可通过 FTP 或者 SFTP 传输到本地

PasswordAuthentication no
AuthenticationMethods publickey
PermitRootLogin prohibit-password
# no为不使用密码
# 使用公钥
# 禁止root使用密码登陆

然后启动 SSH 服务即可

# 开机启动
systemctl enable sshd

# 启动sshd
systemctl start sshd

# 如果已启动,则需要重启服务
systemctl restart sshd
分类: Linux

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据