This page looks best with JavaScript enabled

Ubuntu 新建用户并配置SSH Key登录

 ·  ☕ 1 min read

记录在 Ubuntu Server 上创建用户,并配置其通过 SSH Key File 登录的操作

首先以 root 身份登录

创建用户

这里使用较方便的命令 adduser, 而不是 usesadd。 因为 adduser 相等来说更简单,可以 step by step 的配置

adduser tom

输出:

Adding user `tom' ...
Adding new group `tom' (1001) ...
Adding new user `tom' (1001) with group `tom' ...
Creating home directory `/home/tom' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:

配置好密码之后继续:

Retype new UNIX password:
passwd: password updated successfully
Changing the user information for tom
Enter the new value, or press ENTER for the default
	Full Name []:
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n] y

创建成功

赋予 sudo 权限

查看用户组:

groups tom

// tom: tom

追加到 sodu 组:

usermod -aG sudo tom
groups tom
// tom: tom sudo

配置 SSH 登录

在本地使用 ssh-copy-id 命令,通过 -i 指定 identity_file

ssh-copy-id -i .ssh/id_rsa tom@host

将会自动在 /home/tom/.ssh/authorized_keys 文件追加我们指定的 ssh key. 然后就可以直接 ssh tom@host 免输密码登录了。

Support the author with
alipay QR Code
wechat QR Code

Yang
WRITTEN BY
Yang
Developer