简介
Secure Shell (SSH) 是一个允许两台电脑之间通过安全的连接进行数据交换的网络协议。
通过加密保证了数据的保密性和完整性。SSH采用公钥加密技术来验证远程主机,以及(必要时)允许远程主机验证用户。
常用参数
- SSH端口:22
- Linux中守护进程:sshd
- 安装服务:OpenSSH
- 服务端主程序:/usr/sbin/sshd
- 客户端主程序:/usr/bin/ssh
相关配置文件
- 服务端配置文件:/etc/ssh/sshd_config
- 客户端配置文件:/etc/ssh/ssh_config
SSH加密原理
非对称加密算法
配置文件
Port 22 端口
ListenAddress 0.0.0.0 监听的IP
Protocol 2 SSH版本的选择
HostKey /etc/ssh/ssh_host_rsa_key 私钥保存位置
ServerKeyBits 1024 私钥的位数
SyslogFacility AUTH 日志记录SSH登录情况
LogLevel INFO 日志等级
GSSAPIAuthentication yes GSSAPI认证开启
安全设定部分:
PermitRootLogin yes 允许root的ssh登录
PubkeyAuthentication yes 允许使用公钥验证
AuthorizedKeysFile .ssh/authorized_keys
公钥的保存位置
PasswordAuthentication yes 允许使用密码验证登录
PermitEmptyPasswords no 不允许空密码登录
密钥对登录
创建密钥对
ssh-keygen -t rsa
# 私钥文件:~/.ssh/id_rsa
# 公钥文件:~/.ssh/id_rsa.pub
上传秘钥文件
导入公钥信息
~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
配置服务端/etc/ssh/sshd_config配置文件
vim /etc/ssh/sshd_config
RSAAuthentication yes # 开启rsa验证
PubkeyAuthentication yes # 允许使用公钥验证
AuthorizedKeysFile .ssh/authorized_keys # 公钥的保存位置
PasswordAuthentication no # 允许使用密码验证登录
使用密钥对验证登录
ssh localhost