安裝ssh
yum install openssh
查看端口
netstat -ntpl
netstat -ntpl | grep :22
啟動和關閉
service sshd restart/start/top redhat6版本命令
systemctl restart/start/stop sshd.service redhat7版本命令
隨機啟動
systemctl enable/disable sshd.service
ssh配置文件
/etc/ssh/sshd_config
PermitRootLogin yes/no 是否禁止root遠程登錄
ssh密碼連接命令方式
ssh user@192.168.1.1 -p 22 監聽端口號如果修改,需要 -p 加上端口連接
更改端口未能連接成功,查看防火牆是否關閉
ssh無密碼連接方式
第一種方式:
客戶端配置命令:
ssh-keygen -t rsa //-t 代表rsa加密方式,不加-t默認用rss加密方式 //生成公鑰和私鑰(生成成功后,會在/root/.ssh/目錄下,產生兩個文件id_rsa id_rsa.pub)
scp /root//.ssh/id_rsa.pub root@192.168.1.1:/home/ (服務端IP:192.168.1.1 ,把公鑰cp到服務端的home目錄下)
服務端配置命令:
touch /root/.ssh/authorized_keys 這個文件不存在的話,先創建(存在不需要創建)
cat /home/id_rsa.pub >> /root/.ssh/authorized_keys
以上配置成功,測試是否需要密碼驗證
未能成功,檢查ssh配置文件
PubkeyAuthentication yes/no
第二種方式:
客戶端配置命令:
ssh-kengen 生成公鑰和密鑰
ssh-copy-id /root/.ssh/id_rsa.pub 192.168.1.1 (服務端IP:192.168.1.1 ,把公鑰cp到服務端的/root/.ssh/目錄下)
ssh root@192.168.1.1 測試連接是否需要密碼驗證