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段登陸

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