ssh安装以及配置
大约 1 分钟
ssh安装以及配置
安装的系统为ubuntu20.04 添加apt源:
vim /etc/apt/sources.list
写入以下网址(阿里云):
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
注意这个系统的常规安装是没有ssh需要执行:
apt install openssh-server
这个才是安装ssh服务器的 这个好像给弃用了
apt install sshd
之后使用vim进入配置文件,如果没有vim就安装vim
vim /etc/ssh/sshd_config
需要更改以下配置
PermitRootLogin without-password #允许root账号登录但是不能使用密码,配置期间可使用yes
PubkeyAuthentication yes #允许密钥登录
RSAAuthentication yes #允许使用RSA密钥验证登录
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile .ssh/authorized_keys #配置公钥路径
PasswordAuthentication yes #允许密码登录
ClientAliveInterval 900 #设置超时时间这里是15分钟
ClientAliveCountMax 1 #这里是超时重发判断是否闲置
然后在操作机生成密钥
ssh-keygen -t ed25515 -C "youdoumei"
生成之后将生成的公钥文件(文件后缀为.pub)移动至root(要谁密钥登录就放在谁的用户文件夹)文件夹,如果没有.ssh文件夹新建一个,然后将公钥文件移动到.ssh文件夹里面去,并更名为authorized_keys(这是公钥文件不是文件夹) 最后重启ssh服务
systemctl restart sshd
结束。