Centos7 virtual machine created ssh login

Centos7 virtual machine created ssh login

surroundings

Virtual Machine installed operating system version: CentOS Linux release 7.6.1810 (Core)

Virtual Machine Software Version: VirtualBox 6.0.10 r132072

Creating ssh login user

  1. Log in with administrator privileges

  2. Create a user

    adduser mytestssh
  3. set password

    passwd mytestssh
  4. Give sudo privileges

    gpasswd -a mytestssh wheel

    -a: Add users to the target group

    wheel: the meaning of the steering wheel, a special group of users in linux. Because the root user is very dangerous, so users will need administrator privileges to add to the group, so that the user can use the sudo command.

  5. Under Administrator user query packet

    lid -g wheel

    If we can show the user to add, the above operations are successful.

  6. Rsa key initialization

    ssh-keygen -t rsa -b 4096 -C "[email protected]"

    Instruction will be prompted to enter information, select the appropriate information to fill, can not fill the whole, has been the Enter skip setting.

  7. Open ssh configuration file

    vi /etc/ssh/sshd_config
  8. Found in the file

    #PermitRootLogin yes
    PermitRootLogin yes
    value Whether to allow ssh landing Login Method shell command
    yes Yes Unlimited Unlimited
    without-password Yes You can not log on with a password Unlimited
    forced-commands-only Yes You can only log in with a key You can only have been authorized by the command
    no no

    There are four values ​​PermitRootLogin

    save document

    In front of the # removed.

  9. Start ssh service

    systemctl start sshd.service
  10. Check the ssh service is started successfully

    ps -e | grep sshd
    ss -pltn | grip 22

    It can be seen listening port

    You can see the process, and then check port

  11. Check whether the network is turned on

    ip addr

    Usually have more than one address, the name of the local lo card. If there is no other name card ip address, it is turned off.

  12. Start card

    nmtui

    After this instruction, select the corresponding card, to activate a carriage return.

  13. Virtual machines can not ping

    原因可能是虚拟机网络设置的为NAT模式。如果继续使用NAT模式需要配置端口转发。也可用仅主机能访问的模式。

    这里我们修改为桥接模式。然后检查网卡的IP是不是在同一网段。

  14. ssh连接

    ssh [email protected]

    证书提示选择yes。密码输入正确后进入到虚拟机中。

其他指令

  1. 查看系统版本

    cat /etc/centos-release



Guess you like

Origin blog.51cto.com/5705145/2423582