SecureCRT默认使用root用户连接CentOS7

发生缘由

  • 使用SecureCRT连接CentOS7一直使用的是自己设置的用户,并不是管理员,权限过于的小。于是想着直接一步到位,连接CentOS7的时候直接使用root用户来登录。

  • 我之前已经将防火墙、ssh什么的都弄好了。

环境介绍

  • 电脑系统:win10

  • 虚拟机:VMware15虚拟机

  • linux系统:CentOS7

  • SecureCRT:SecureCRT8.5

动手设置

SecureCRT中Ctrl + Shift + C代表复制,Ctrl + Shift + V代表粘贴。

  1. 设置root用户密码

    root用户默认是不设置密码的,我们需要来手动设置一下。

    找一个用户通过SecureCRT来连接CentOS,当然肯定不是root用户。然后键入如下代码:sudo passwd root,这会要求输入当前用户登录的密码,验证成功后会让你设置root用户密码以及重复输入。

    [linxuan@192 ~]$ sudo passwd root
    [sudo] password for linxuan:                  # 输入linxuan用户的密码
    Changing password for user root.
    New password:                                 # 输入需要为root用户设置的密码
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password: # 确认输入为root用户设置的密码
    passwd: all authentication tokens updated successfully.
  2. 登录root用户,让CentOS重启。

    [linxuan@192 ssh]$ su                       # 切换root用户
    Password:            # 输入上面设置root用户的密码
    [root@192 ssh]# reboot # 重启CentOS
  3. 使用SecureCRT连接CentOS,不过这次使用root用户连接。 如果出现该信息

    Password Authentication Failed
    Password authentication failed. Please verify that the username and password are correct.
    All available GSSAPI mechanisms failed.

    那么需要修改一下Centos的配置了。如果没有出现该信息,那么代表连接成功,就不用下面的步骤了。

  4. 修改一下ssh配置文件

    [root@192 ssh]# vim /etc/ssh/sshd_config                        # 使用Vim打开sshd_config文件

    接着会出现下面的代码:

    #       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

    # This is the sshd server system-wide configuration file. See
    # sshd_config(5) for more information.

    # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

    # The strategy used for options in the default sshd_config shipped with
    # OpenSSH is to specify options with their default value where
    # possible, but leave them commented. Uncommented options override the
    # default value.

    # If you want to change the port on a SELinux system, you have to tell
    # SELinux about this change.
    # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
    #
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::

    HostKey /etc/ssh/ssh_host_rsa_key
    HostKey /etc/ssh/ssh_host_ecdsa_key
    HostKey /etc/ssh/ssh_host_ed25519_key

    # Ciphers and keying
    #RekeyLimit default none

    # System-wide Crypto policy:
    # This system is following system-wide crypto policy. The changes to
    # Ciphers, MACs, KexAlgoritms and GSSAPIKexAlgorithsm will not have any
    # effect here. They will be overridden by command-line options passed on
    # the server start up.
    # To opt out, uncomment a line with redefinition of CRYPTO_POLICY=
    # variable in /etc/sysconfig/sshd to overwrite the policy.
    # For more information, see manual page for update-crypto-policies(8).

    # Logging
    #SyslogFacility AUTH
    SyslogFacility AUTHPRIV
    #LogLevel INFO

    # Authentication:

    #LoginGraceTime 2m
    #PermitRootLogin no   # 将其修改一下
    #StrictModes yes
    #MaxAuthTries 6
    #MaxSessions 10

    i进入插入模式(界面左下角显示--INSERT--字样),将光标移动到#PermitRootLogin no,将该行修改为

    PermitRootLogin yes    # 注释删除,no改为yes

    键盘按下Esc键回到普通模式(界面左下角的--INSERT--标志消失),手动输入:wq储存后退出。

    保险起见,我们可以看一下该文件是否真的被我们修改了,使用下面命令将文件信息回显到屏幕。

    [root@192 ssh]# cat /etc/ssh/sshd_config

    鼠标齿轮向上滑动,找到PermitRootLogin yes ,可以发现已经修改成功了。

    接下来就是重启该服务了。

    [root@192 ssh]# service sshd restart    
    Redirecting to /bin/systemctl restart sshd.service
  5. 这样使用Root用户连接就没有问题了。

posted @ 2022-07-30 22:38  炸天帮帮主  阅读(270)  评论(0编辑  收藏  举报