centos7修改22端口,新增管理员账号,禁止root远程连接

centos7修改22端口,新增管理员账号,禁止root远程连接

新增管理员账号

  1. 新建用户,这里新建一个temp_test的用户

    adduser temp_test
    

  2. 设置新用户密码

    passwd temp_test 
    

  3. 将sudoers文件的权限修改成可编辑

    chmod -v u+w /etc/sudoers
    

  4. 使用vim编辑sudoers文件

    vim /etc/sudoers
    

  5. 在sudoes文件中添加如下的内容

    找到root       ALL=(ALL)           ALL
    
    然后添加temp_user     ALL=(ALL)       ALL
    
    如需新用户使用sudo时不用输密码,把最后一个ALL改为NOPASSWD:ALL即可。
    
    

  6. 将sudoers文件的权限修改成不可编辑

    chmod -v u-w /etc/sudoers
    

修改22端口

  1. 修改配置文件

    vim /etc/ssh/sshd_config
    找到 # port
    

  2. 另起一行。如定义SSH端口号为57122,则输入Port 57122自定义端口选择建议在万位的端口(如:10000-65535之间)

    #Port 22
    Port 8467
    

  3. 按下esc键后,输入:wq进行保存

  4. 重启ssh服务

    service sshd restart 
    
    如果显示: Redirecting to /bin/systemctl restart sshd.service
    就通过 systemctl 操作
    
    1、查看 sshd 服务是否启动:
    	systemctl status sshd.service
    2、如果没有启动,则需要启动该服务:
    	systemctl start sshd.service
    3、重启 sshd 服务:
    	systemctl restart sshd.service
    4、设置服务开启自启:
    	systemctl enable sshd.service
    

禁止root远程连接

  1. 首先,我们要以root身份登录远程主机

  2. vim指令编辑ssh配置文件,如

    vim /etc/ssh/sshd_config
    

  3. 查找PermitRootLogin,把yes改为no

    UseDNS no
    AddressFamily inet
    SyslogFacility AUTHPRIV
    PermitRootLogin yes # 把这个改成no
    PasswordAuthentication yes
    

  4. 修改完配置需要重启ssh服务

    service sshd restart
    
    如果显示: Redirecting to /bin/systemctl restart sshd.service
    就通过 systemctl 操作
    
    1、查看 sshd 服务是否启动:
    	systemctl status sshd.service
    2、如果没有启动,则需要启动该服务:
    	systemctl start sshd.service
    3、重启 sshd 服务:
    	systemctl restart sshd.service
    4、设置服务开启自启:
    	systemctl enable sshd.service
    

猜你喜欢

转载自blog.csdn.net/Python_anning/article/details/108995498