RHCSA教程 第十章 OPENSSH服务
1.ssh的常用功能
[root@servera ~]# ssh serverb
root@serverb's password: 
[root@servera ~]# vim /etc/hosts  或者系统是否做了dns,ip和域名及主机名的映射
[root@servera ~]# ssh 172.25.250.11
[root@servera ~]# ssh root@172.25.250.11
[root@servera opt]# scp rhcetext root@172.25.250.11:/
root@172.25.250.11's password: 
rhcetext                                                 100%    0     0.0KB/s   00:00
[root@serverb /]# scp root@172.25.250.10:/opt/newfile  .
root@172.25.250.10's password: 
newfile                                                  100%    0     0.0KB/s   00:00 
[root@servera opt]# ssh root@172.25.250.11 'yum install -y httpd'
ssh root@172.25.250.11 'yum install -y httpd'
2.ssh免密登录
【servera】
[root@servera ssh]# ssh-keygen  后面三个回车
[root@servera ssh]# ssh-copy-id  root@serverb
【serverb】
[root@serverb /]# cd /root/.ssh/
[root@serverb .ssh]# ls
authorized_keys  known_hosts
【servera】
[root@servera ssh]# ssh root@serverb
a免密远程b,如果想b远程a免密,需要相同的配置
 课上练习:b远程免密登录a
3.ssh服务控制
拒绝root登录
[root@serverb ~]# vim /etc/ssh/sshd_config
PermitRootLogin no
[root@serverb ~]# systemctl reload sshd(或restart)
[root@servera ~]# ssh root@serverb
4.sudo
一、将用户设置为特权用户
1、
[student@servera ~]$ yum remove -y httpd
Error: This command has to be run under the root user.
2、
[root@servera /]# vim /etc/sudoers    或者 visudo
## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
student ALL=(ALL)       ALL
3、
[student@servera ~]$ sudo yum remove -y httpd
[sudo] password for student: student
二、将账号添加到特权用户组中,培训环境默认特权用户组是wheel组,在/etc/sudoers文件中用%wheel来表示
usermod -G wheel tom
三、练习:
添加一个特权组admin,而且组内有一个成员是harry。最终harry账号应当为特权账号。
[root@serverb ~]# groupadd admin
[root@serverb ~]# visudo
[root@serverb ~]# useradd -G admin  harry
[root@serverb ~]# su - harry
[harry@serverb ~]$ sudo -i
[sudo] password for harry: 
四、设置特权组中用户切换时不需要密码
%admin  ALL=(ALL)       NOPASSWD: ALL
        THE END
    
        
        
