同系列文章:
一、什么是SSH
SSH 为 Secure Shell的缩写,由 IETF 的网络小组(Network Working Group)所制定;它是建立在应用层基础上的安全协议。
SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。
SSH最初是UNIX系统上的一个程序,后来又迅速扩展到其他操作平台。
二、安装openssh server
sudo apt install openssh-server
三、生成密钥
说明:splash为个人办公电脑Ubuntu系统的登录用户名。保留id_rsa_splash.pub公钥文件,将id_rsa_splash私钥文件放置于客户端主机。
ssh-keygen -t rsa -f ~/.ssh/id_rsa_splash -C "splashcn@sina.com"
四、更改公钥文件调用权限
cd ~/.ssh chmod 600 id_rsa_splash.pub
五、修改服务器端配置文件,实现免密通信
sudo gedit /etc/ssh/sshd_config
修改内容
#设置端口 #Port 22 #开启公钥验证 PubkeyAuthentication yes #设置公钥验证文件路径(符号%u表示登录用户名) #AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 AuthorizedKeysFile .ssh/id_rsa_%u.pub #关闭密码验证机制 PasswordAuthentication no #显示图形界面 X11Forwarding yes
六、启动SSH服务
sudo service ssh start
七、SSH相关命令
#启动服务 sudo service ssh start sudo /etc/init.d/ssh start #停止服务 sudo service ssh stop sudo /etc/init.d/ssh stop #重新启动服务 sudo service ssh restart sudo /etc/init.d/ssh restart #查看SSH是否启动 ps -e | grep ssh #查看SSH状态 service ssh status #设置ssh开机自启动 sudo systemctl enable ssh #禁止SSH开机自启动 sudo systemctl disable ssh