【Linux operation 48】Ubuntu启用root用户,并授予远程ssh访问权限

ubuntu系统服务器,默认的登陆用户名为ubuntu,那很多用户都想使用超级管理员root用户来操作自己的服务器,但是root用户默认是被禁止登陆的,该如何启用root用户呢?操作方法如下:

1、使用自己创建的 ubuntu 帐户登录应用服务器

在这里插入图片描述

2、设置 root 密码

sudo passwd root

输入两遍密码;
返回如下信息,即表示 root 密码设置成功。

passwd: password updated successfully

在这里插入图片描述

3、下载vim、ssh服务

sudo apt install vim
sudo apt install ssh
root@test-virtual-machine:/etc/ssh# apt install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  vim-common vim-runtime vim-tiny
Suggested packages:
  ctags vim-doc vim-scripts indent
The following NEW packages will be installed:
  vim vim-runtime
The following packages will be upgraded:
  vim-common vim-tiny
2 upgraded, 2 newly installed, 0 to remove and 70 not upgraded.
Need to get 8,560 kB/9,345 kB of archives.
After this operation, 37.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim-runtime all 2:8.2.3995-1ubuntu2.1 [6,832 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim amd64 2:8.2.3995-1ubuntu2.1 [1,727 kB]
Fetched 8,560 kB in 3s (2,712 kB/s)
(Reading database ... 195574 files and directories currently installed.)
Preparing to unpack .../vim-tiny_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim-tiny (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Preparing to unpack .../vim-common_2%3a8.2.3995-1ubuntu2.1_all.deb ...
Unpacking vim-common (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Selecting previously unselected package vim-runtime.
Preparing to unpack .../vim-runtime_2%3a8.2.3995-1ubuntu2.1_all.deb ...
Adding 'diversion of /usr/share/vim/vim82/doc/help.txt to /usr/share/vim/vim82/
doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim82/doc/tags to /usr/share/vim/vim82/doc/
tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:8.2.3995-1ubuntu2.1) ...
Selecting previously unselected package vim.
Preparing to unpack .../vim_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim (2:8.2.3995-1ubuntu2.1) ...
Setting up vim-common (2:8.2.3995-1ubuntu2.1) ...
Setting up vim-runtime (2:8.2.3995-1ubuntu2.1) ...
Setting up vim (2:8.2.3995-1ubuntu2.1) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in 
auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimd
iff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) i
n auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview)
 in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in au
to mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) i
n auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in au
to mode
Setting up vim-tiny (2:8.2.3995-1ubuntu2.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
root@test-virtual-machine:/etc/ssh# apt install ssh
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
Suggested packages:
  molly-guard monkeysphere ssh-askpass
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh ssh-import-id
0 upgraded, 5 newly installed, 0 to remove and 70 not upgraded.
Need to get 756 kB of archives.
After this operation, 6,179 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 openssh-sftp-server amd64 1:8.9p1-3 [38.8 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 openssh-server amd64 1:8.9p1-3 [434 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 ssh all 1:8.9p1-3 [4,834 B]
Get:4 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 ncurses-term all 6.3-2 [267 kB]
Get:5 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 ssh-import-id all 5.11-0ubuntu1 [10.1 kB]
Fetched 756 kB in 3s (264 kB/s)     
Preconfiguring packages ...
Selecting previously unselected package openssh-sftp-server.
(Reading database ... 197515 files and directories currently installed.)
Preparing to unpack .../openssh-sftp-server_1%3a8.9p1-3_amd64.deb ...
Unpacking openssh-sftp-server (1:8.9p1-3) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a8.9p1-3_amd64.deb ...
Unpacking openssh-server (1:8.9p1-3) ...
Selecting previously unselected package ssh.
Preparing to unpack .../ssh_1%3a8.9p1-3_all.deb ...
Unpacking ssh (1:8.9p1-3) ...
Selecting previously unselected package ncurses-term.
Preparing to unpack .../ncurses-term_6.3-2_all.deb ...
Unpacking ncurses-term (6.3-2) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.11-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.11-0ubuntu1) ...
Setting up openssh-sftp-server (1:8.9p1-3) ...
Setting up openssh-server (1:8.9p1-3) ...

Creating config file /etc/ssh/sshd_config with new version
Creating SSH2 RSA key; this may take some time ...
3072 SHA256:8GWMrs0KbgauxIy3zIrN3L+ZS4Pdv9X30sJ81Pm8Xr4 root@test-virtual-machi
ne (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:7TK7qy8o1RM+MtD+7GcJtp07b3843uHNm84XUIdY1W8 root@test-virtual-machin
e (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:MozIziCL1cvOtJDgHeP2O/Wu+stbjpfFQTeXpkxmuzA root@test-virtual-machin
e (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.serv
ice.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/
systemd/system/ssh.service.
rescue-ssh.target is a disabled or a static unit, not starting it.
ssh.socket is a disabled or a static unit, not starting it.
Setting up ssh-import-id (5.11-0ubuntu1) ...
Setting up ncurses-term (6.3-2) ...
Setting up ssh (1:8.9p1-3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for ufw (0.36.1-4build1) ...

4、开启root用户ssh远程密码登录

编辑/etc/ssh/sshd_config文件

sudo vim /etc/ssh/sshd_config

将PermitRootLogin prohibit-password更改为:PermitRootLogin yes

最后重启ssh服务即可

sudo  systemctl  restart  ssh

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值