SSH is the abbreviation for Secure Shell, which is provided by the IETF Network Group (Working Group)
SSH is a network protocol that is used to encrypt logins between computers. If a user logs on to another remote computer using the SSH protocol from the local computer, we can assume that the login is secure, and that the password will not be compromised even if intercepted in the middle. The earliest time, the Internet communication is clear communication, once intercepted, the content is undoubtedly exposed. In 1995, Finnish scholar Tatu Ylonen designed the SSH protocol to encrypt all login information and become a basic solution for Internet security, which has become a standard configuration for Linux systems. SSH is only a protocol, it is free software, the application is very extensive.
1:客户机 #ssh [email protected] //在linux远程访问192.168.100.101 sshd服务是默认允许root用户登录的 但这是非常不安全的 普遍的做法是:先登录普通用户 根据实际需求使用su 切换root用户
2:服务器下面设置 禁止root用户登录vim /etc/ssh/sshd_config //(ssh主配置文件) PermitRootLogin no // 拒绝root 用户登录 Allowusers zzz zkc //只允许zzz zkc 用户登录 service sshd restart //重启服务
3:服务器创建一个用户zzz (我系统里有个zkc用户了) 但此时zzz zkc 用户 都能使用su 切换到root用户 所以不是很安全所以下面配置 : 禁止普通用户切换root用户 只给zzz 用户切换root 的权限#gpasswd -a zzz wheel //将zzz 加入wheel #vi /etc/pam.d/su //认证配置 auth required pam_wheel.so use_uid //去掉此行开头的 # 号
4:到客户机 上测试下 成功 ssh @root192.168.100.101 无法登录 ssh @zkc192.168.100.101 可以登录 无法切换root ssh @zzz192.168.100.101 可以登录 可以切换
5:切换到ssh服务器上 配置SSH密钥 #vi /etc/ssh/sshd_config //编辑sshd_config PubkeyAuthentication yes //启用密钥对验证 AuthorizedKeysFile .ssh/authorized_keys //指定公钥数据文件 service sshd restart //重启sshd服务
6:回到客户机上 useradd benent //创建用户benet passwd benet //设置benet用户密码 su - benet //切换用户到benet ssh-keygen -t rsa //创建密钥对 (设置私钥短语 确认私钥短语) ls -a /home/benet/.ssh // 查看私钥位置(密钥文件为隐藏文件 用 -a) cd /home/benet/.ssh //到私钥存放目录
7:ssh-copy-id -i id_rsa.pub [email protected] //将公钥上传到服务器 ( 公钥在服务器的 /home/zzz/.ssh 下面)ssh [email protected] //使用ssh登录服务器上的zzz 用户 (此时只要输入私钥短语就能登录了)//在客户机上设置ssh 代理功能 不需要设置密码就能访问//ssh-agent bash ssh-add
Linux redhat6.5 build SSH service and SSH build key pair authentication