CentOS SSH 配置文件位置与修改要点
主要配置文件位置
sudo vi /etc/ssh/sshd_config。nano ~/.ssh/config。修改与生效步骤
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.baksudo vi /etc/ssh/sshd_configsudo systemctl reload sshdsudo systemctl restart sshdsudo systemctl status sshd(应显示 active (running))。常见修改与示例
#Port 22 改为 Port 2222(去掉行首注释),保存后重启并在连接时使用 -p 2222。ListenAddress 0.0.0.0(所有接口)或 127.0.0.1(仅本地),保存后重启。PasswordAuthentication no 并确保 PubkeyAuthentication yes,保存后重启。sudo firewall-cmd --permanent --add-port=2222/tcp && sudo firewall-cmd --reload。客户端配置示例 ~/.ssh/config
touch ~/.ssh/config && chmod 600 ~/.ssh/configHost server1
HostName 192.0.2.10
User alice
Port 2222
IdentityFile ~/.ssh/id_rsa_server1
Host github.com
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_rsa_github
ssh server1;验证参数:ssh -G server1。