前置步骤
1、购买服务器
2、加入安全组
3、修改实例名称,修改实例密码
配置SSH登录
1 查看ssh配置
cat /etc/ssh/sshd_config
2 安装SSH
sudo apt-get install ssh #ubuntu,debian
or
yum -y install openssh #centos,redhat
3 启动服务
service sshd start
or
/bin/systemctl restart sshd.service
or
/etc/init.d/sshd start
or
sudo systemctl restart sshd
4 查看ssh服务的状态
输入以下命令:
sudo service sshd status
如果出现
Loaded: error (Reason: No such file or directory)
提示的话,说名没有安装ssh服务,按照第二步:安装ssh服务。
如果出现
Active: inactive (dead)
说明已经安装了ssh服务,但是没有开启。按照第三步:开启ssh服务。
如果出现
Active: active (running) since XXX
说明已经成功了
大致步骤为:
SSH 服务配置文件位置
/etc/ssh/sshd_config
# 修改配置
PasswordAuthentication yes
PermitRootLogin yes
# 启动SSH 服务
service sshd start/stop/status
安装SSH:yum install ssh
启动SSH: service sshd start
重启SSH: service sshd restart
设置开机运行: chkconfig sshd on
5 在电脑终端输入
ssh root@47.96.118.128
(输入服务器密码)
配置ssh免密码登录
1.添加文件
vi /root/.ssh/authorized_keys //创建文件authorized_keys
authorized_keys 存放公钥,远程使用私钥登陆
chmod 600 /root/.ssh/authorized_keys //加权限
chmod 700 /root/.ssh/ //加权限
2.添加公钥到文件内(id_rsa.pub)
这里是在本地电脑端生成
ssh-keygen -t rsa
密钥名称和密码可以不填 默认即可,密码默认空
image.png
vi /root/.ssh/authorized_keys
输入`i`进入编辑模式
粘贴进去公钥
按`esc`退出编辑模式
按 `:wq!`退出并保存(按`:qa!`退出不保存)
image.png
3.编辑ssh配置文件:
vi /etc/ssh/sshd_config //编辑ssh配置文件
PermitRootLogin yes // 禁止root远程登录,可选项
PasswordAuthentication yes //使用基于口令认证的方式登陆,默认yes,可选项
//新增以下3个配置
PubkeyAuthentication yes //允许使用基于密钥认证的方式登陆,必选项
RSAAuthentication yes // 启用 RSA 认证 ,可选项
AuthorizedKeysFile .ssh/authorized_keys // 公钥文件路径,可选项
4.重启sshd服务
service sshd restart
5 在电脑终端输入
ssh root@47.96.118.128
(不用输入密码了)
常见错误:
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:sbd8mG3CPJc81mLgPPwLwVy7LF8qvUUuXisbcPKzTyE.
Please contact your system administrator.
Add correct host key in /Users/admin/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/admin/.ssh/known_hosts:12
ECDSA host key for 47.96.118.128 has changed and you have requested strict checking.
Host key verification failed.
解决办法如下 输入
rm -rf ~/.ssh/known_hosts
然后重新连接即可。
网友评论