ssh使用手册

ssh配置

ubuntu20.04

安装
sudo apt -y install openssh-server
查看状态
sudo systemctl status sshd
启动
sudo systemctl start sshd
查看ip
sudo ip addr show
客户端连接
ssh [email protected]

CentOS8.1.1911

查看安装状态
rpm -qa | grep ssh
安装
服务器端 dnf -y install openssh-server
客户端 dnf -y install openssh-client
重装

主程序
服务器端 /usr/sbin/sshd
客户端 /usr/bin/ssh
配置文件
服务器端 /etc/ssh/sshd_config
客户端 /etc/ssh/ssh_config
服务器配置文件内容
Prot22 端口
ListenAddress 0.0.0.0 监听主机的的IP(设置后只有指定IP才监听)
Hostkey /etc/ssh/ssh_host_rsa_key 私钥保存位置
SyslogFacility AUTH 日志记录ssh登陆情况
LogLevel INFO 日志等级
PermitRootLogin yes 允许root用户登陆
PubkeyAuthentication yes 是否使用公钥验证
AuthorizedKeysFile .ssh/autorized_keys 公钥保存位置
PasswordAuthentication yes 允许使用密码验证登陆
PasswordEmptyPasswords no 不允许空密码登陆
文件下载
scp username@address:destfile localdir
文件上传
scp -r localdir(file) username@address:destdir

实验1
设置只允许密钥登陆
1、client端生成密钥对
ssh-keygen -t rsa 保存位置~/.ssh/id_rsa
2、上传公钥到服务器,将其写入配置文件
scp ~/.ssh/id_rsa.pub [email protected]:/root
cat id_rsa.pub >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
3、修改服务器端配置文件
PubkeyAuthentication yes 开启公钥验证
AuthorizedKeyFile .ssh/authorized_keys 公钥保存位置
PasswordAuthentication no 禁止使用密码验证登陆
4、重启sshd服务
systemctl restart sshd.service
注意事项:如果不能连接需要关闭SELinux服务
vim /etc/selinux/config
将SELINUX=enfrcing改为SELINUX=disabled
实验2
设置只允许指定IP地址/IP段登陆

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章