一、修改SSH默认端口
vi /etc/ssh/sshd_config #打开配置文件路径
...
Port 10022 #CentOS需要semanage port -a -t ssh_port_t -p tcp 10022,为了安全
#HostKey /etc/ssh/ssh_host_rsa_key #Hostkey目录
#PubkeyAuthentication yes #Pubkey默认开启
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 #授权密钥保存目录
PasswordAuthentication yes #no表示root用户用ssh登录方式不再验证密码
#配置Port后,阿里云安全组需要增加此端口范围并执行 service ssh restart 才可生效
二、SSH密钥登录
如:ssh zxp(免密码)代替ssh root@47.100.103.92快速启动
1、本机查看ssh key
没有ssh key,需要通过ssh-keygen生成
cat ~/.ssh/id_rsa.pub
2、进入阿里云服务器,保存ssh key到authorized_keys 文件
vi ~/.ssh/authorized_keys
3、本机vi ~/.ssh/config 进入到config配置,末尾添加如下
zxp为ssh zxp #启动的名称, ip地址HostName#为ssh登录的服务器(阿里云外网ip)User#需要ssh登录的用户名IdentityFile#远程服务器密钥路径IdentitiesOnly#使用唯一的私钥文件,以避免其他私钥文件的干扰
Host zxp
Port 10022
HostName 47.100.103.92
User root
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes