欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ssh以root用户登录ubuntu服务器

程序员文章站 2022-06-05 18:38:12
...
  • 更改root密码

    一般情况安装Ubuntu时,不会提示root用户的相关信息,自然无法知道root用户的密码.Ubuntu的root用户的密码是随机的,即每一次开机,都有一个新的root密码.我们在以其他用户进入系统后,可以使用sudo passwd 命令修改密码,输入新的密码后,此时的密码就是root用户的密码.之后再输入su root 就用这个密码就可以了.

  • 用ssh 以root用户登录服务器

    有了root用户的密码,还不能用ssh登录该服务器,因为ssh默认是阻止以root用户进行远程登录的.

    要使用root 用户登录,需要更改配置文件,做一下操作

    [email protected]:~
    $ ssh [email protected].168.122.xxx #以普通用户登录
    [email protected].168.122.xxx's password: 
    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-36-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
      System information as of Thu Oct 25 08:09:04 UTC 2018
    
      System load:  0.0               Processes:           93
      Usage of /:   7.6% of 97.93GB   Users logged in:     0
      Memory usage: 9%                IP address for ens3: 192.168.122.190
      Swap usage:   0%
    
     * Security certifications for Ubuntu!
       We now have FIPS, STIG, CC and a CIS Benchmark.
    
       - http://bit.ly/Security_Certification
    
     * Want to make a highly secure kiosk, smart display or touchscreen?
       Here's a step-by-step tutorial for a rainy weekend, or a startup.
    
       - https://bit.ly/secure-kiosk
    
    
     * Canonical Livepatch is available for installation.
       - Reduce system reboots and improve kernel security. Activate at:
         https://ubuntu.com/livepatch
    
    28 packages can be updated.
    0 updates are security updates.
    
    
    Last login: Thu Oct 25 08:00:28 2018 from 192.168.122.1
    [email protected]:~$ su root  #切换到root用户
    Password: 
    #修改配置文件
    [email protected]:/home/eric# vim /etc/ssh/sshd_config
    
    -----注释掉 PermitRootLogin without-password
    ------添加 PermitRootLogin yes
    
    #####重启服务
    [email protected]:/home/eric# /etc/init.d/ssh restart
    [ ok ] Restarting ssh (via systemctl): ssh.service.
    [email protected]:/home/eric# exit
    
    #退出后重新以root登录
    
    [email protected]:~
    $ ssh [email protected].168.122.xxx
    [email protected].168.122.xxx's password: 
    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-36-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
      System information as of Thu Oct 25 08:13:38 UTC 2018
    
      System load:  0.0               Processes:           95
      Usage of /:   7.6% of 97.93GB   Users logged in:     0
      Memory usage: 9%                IP address for ens3: 192.168.122.190
      Swap usage:   0%
    
     * Security certifications for Ubuntu!
       We now have FIPS, STIG, CC and a CIS Benchmark.
    
       - http://bit.ly/Security_Certification
    
     * Want to make a highly secure kiosk, smart display or touchscreen?
       Here's a step-by-step tutorial for a rainy weekend, or a startup.
    
       - https://bit.ly/secure-kiosk
    
    
     * Canonical Livepatch is available for installation.
       - Reduce system reboots and improve kernel security. Activate at:
         https://ubuntu.com/livepatch
    
    28 packages can be updated.
    0 updates are security updates.
    
    
    
    The programs included with the Ubuntu system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    
    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
    applicable law.
    
    #登录成功
    [email protected]:~#
    
    
相关标签: ssh ubuntu server