安装ssh环境
2018-11-29 本文已影响0人
吟风者
1 配置root用户密码
1.1 修改root用户的初始密码
sudo passwd

退出当前用户,使用root登陆系统。
1.2 关闭防火墙
关闭防火墙
systemctl stop firewalld.service
开机不启动防火墙
systemctl disable firewalld.service
查看防火墙状态
ufw status
inactive
状态是防火墙关闭状态,active
是开启状态。
1.3 配置root用户远程连接
(注:server版ubuntu默认安装了ssh-server
,如果未安装,请先安装)
apt-get install openssh-server
修改sshd_config
vim /etc/ssh/sshd_config
找到
# Authentication:
LoginGraceTime 2m
PermitRootLogin without-password
StrictModes yes
改成
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
然后重启SSH服务即可。
重启过后通过shell连接:

1.4 设置ssh免密码登录
ssh localhost
exit
输入密码登录本机和退出本机

在进行了初次登陆后,会在当前家目录用户下有一个.ssh文件夹,进入该文件夹下:
cd ~/.ssh/
使用rsa算法生成秘钥和公钥对:
ssh-keygen -t rsa

运行后一路回车就可以了,其中第一个是要输入秘钥和公钥对的保存位置,默认是在~/.ssh/。
然后把公钥加入到授权中:
cat ./id_rsa.pub >> ./authorized_keys
再次ssh localhost的时候就可以无密码登陆了。