在 vps 的 root 账户下
yum install vim-enhanced.x86_64
vim /etc/ssh/sshd_config #按 i 进入编辑
确保(去掉注释#)
RSAAuthentication yes #允许 RSA 认证
PubkeyAuthentication yes #允许公钥认证
PermitRootLogin no #禁止 ROOT 通过 SSH 登陆
PasswordAuthentication no #禁止密码登陆
ChallengeResponseAuthentication no # 禁止使用任何的密码登陆
修改端口, 将 #Port 22 改为 Port XXX #改掉默认端口
按 esc 退出编辑,:wq #保存并退出 sshd_config
service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
然后
service iptables start #直接启动 iptables 服务。
iptables -A INPUT -p tcp --dport XXX -j ACCEPT
iptables -I OUTPUT -p tcp --sport XXX -j ACCEPT
service iptables save #保存
Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
control+D 断开 SSH 的连接
我尝试在本地建立一个 config
vi ~/.ssh/config #在私钥所在的.ssh 文件夹内新建一个 config 文件
按 i 编辑,复制以下内容
Host vps #这个名字随意,感觉像调用函数
HostName IP_address #IP 地址或服务器域名
Port XXX #服务器端开放的 ssh 端口 之前把 22 改为 XXX
User 非 root #登录的用户名
IdentityFile ~/.ssh/id_rsa #使用的密钥文件密钥文件,本地私钥地址
按 esc 退出编辑,输入:wq 退出并保存
ssh vps
ssh: connect to host IP_address port XXX: Connection refused
我之前设置SSH key的时候有Enter passphrase (empty for no passphrase): 123456 和这个有关吗?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.