CentOS开启SSH远程root登陆

本文最后更新于1 分钟前,文中所描述的信息可能已发生改变。

说明

  • 买的腾讯云的服务器,默认关闭了ssh的远程登陆,需要设置开启。
  • 腾讯云的可以在管理页面的中间找到这个按钮,能够开启网页版的远程登陆窗口。 shell登录

开启ssh远程root用户登陆:

首先登陆进来的用户不是root用户,为了修改sshd_config配置,需要使用root用户。

使用命令sudo -s 切换到root用户: sudo -s/etc/ssh目录下有一个sshd_config 文件,

[root@VM-16-4-centos ssh]# ll
total 612
-rw-r--r-- 1 root root 581843 Oct 19 22:06 moduli
-rw-r--r-- 1 root root   2276 Oct 19 22:06 ssh_config
-rw------- 1 root root   3944 Dec 21 17:32 sshd_config
-rw------- 1 root root    668 Dec 21 17:27 ssh_host_dsa_key
-rw-r--r-- 1 root root    609 Dec 21 17:27 ssh_host_dsa_key.pub
-rw------- 1 root root    227 Dec 21 17:27 ssh_host_ecdsa_key
-rw-r--r-- 1 root root    181 Dec 21 17:27 ssh_host_ecdsa_key.pub
-rw------- 1 root root    411 Dec 21 17:27 ssh_host_ed25519_key
-rw-r--r-- 1 root root    101 Dec 21 17:27 ssh_host_ed25519_key.pub
-rw------- 1 root root   1679 Dec 21 17:27 ssh_host_rsa_key
-rw-r--r-- 1 root root    401 Dec 21 17:27 ssh_host_rsa_key.pub
[root@VM-16-4-centos ssh]# pwd
/etc/ssh
[root@VM-16-4-centos ssh]#

编辑sshd_config 文件

[root@VM-16-4-centos ssh]# vim sshd_config
开启下面两项配置#LoginGraceTime 2m
PermitRootLogin yes                    #开启root登陆配置
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes              #开启密码验证登陆
#PermitEmptyPasswords no
#PasswordAuthentication no


#### 重启ssh服务,使配置生效:

[root@VM-16-4-centos ssh]# service sshd restart


#### 修改root用户密码:

[root@VM-16-4-centos ssh]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@VM-16-4-centos ssh]#

按照我上面的操作补助来进行配置修改

验证

使用ssh远程客户端登陆验证吧~

完结撒花~~~

CentOS7安装Docker
docker中运行codeserver实现云编程