转自:https://linuxize.com/post/how-to-create-a-sudo-user-on-ubuntu/


The sudo command is designed to allow users to run programs with the security privileges of another user, by default the root user.

In this guide, we will show you how to create a new user on an Ubuntu machine and give it sudo access. You can then use this user account to execute administrative commands without a need to logging in to your Ubuntu server as a root user.

Steps to create a sudo user

Follow the steps below to create a new user account and give it sudo access. If you want to configure sudo for an existing user, skip to step 3.

1. Log in to your server.

Log in to your system as the root user:

ssh root@server_ip_address

Copy

2. Create a new user account.

Create a new user account using the adduser command. Don’t forget to replace usernamewith the user name that you want to create:

adduser username

Copy

You will be prompted to set and confirm the new user password. Make sure that the password for the new account is as strong as possible.

Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully

Copy

Once you set the password the command will create a home directory for the user, copy several configuration files in the home directory and prompts you to set the new user’s information. If you want to leave all of this information blank just press ENTER to accept the defaults.

Changing the user information for username
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]

Copy

3. Add the new user to the sudo group

By default on Ubuntu systems, members of the group sudo are granted with sudo access. To add the user you created to the sudo group use the usermod command:

usermod -aG sudo username

Copy

 

Test the sudo access

Switch to the newly created user:

su - username

Copy

Use the sudo command to run the whoami command:

sudo whoami

Copy

Is the user have sudo access then the output of the whoami command will be root:

root

Copy

How to use sudo

To use sudo, simply prefix the command with sudo and space:

sudo ls -l /root

Copy

The first time you use sudo in a session, you will be prompted to enter the user password:

[sudo] password for username:

Copy

Conclusion

You have learned how to create a user with sudo privileges. You can now log in to your Ubuntu server with this user account and use sudo to run administrative commands.

That’s all! Feel free to leave a comment if you have any questions.

(转)How To Create a Sudo User on Ubuntu的更多相关文章

  1. How to create a PPPoE Server on Ubuntu? (Untested)

    How to create a PPPoE Server on Ubuntu? March 30, 2011 coder_commenter Leave a comment Go to comment ...

  2. Create & use FTP service on Ubuntu(在Ubuntu上搭建并使用FTP服务)

    Check if the FTP service has been installed.(检查是否已安装)   Vsftpd --version  If it has not install,Pres ...

  3. linux学习: sudo命令(ubuntu)

    使用 sudo 命令可以提高命令的执行权限,以root权限执行 如 :  sudo vi xxx 但是有些内置命令 如 cd 无法通过 sudo来执行 ,如  sudo cd xxx 这是会报错的. ...

  4. Linux服务器新建用户和组,并分配sudo权限 (Ubuntu系统)

    新拿到一台服务器后我们一般都是要新建用户组,用户,并为其分配权限. ==================================================== 赋予用户组sudo权限: ...

  5. ubuntu创建sudo 用户

    The sudo command provides a mechanism for granting administrator privileges, ordinarily only availab ...

  6. 【linux】linux创建用户并授予sudo权限

    1. 新建用户 root@ubuntu:~# adduser hadoop root@ubuntu:~# passwd hadoop #为hadoop用户设置密码 2. 为hadoop用户添加sudo ...

  7. unbuntu下的root 用户和 sudo 命令

    参考: http://james23dier.iteye.com/blog/721246 http://blog.csdn.net/shichexixi/article/details/5969993 ...

  8. 【新技术】Docker 学习笔记

    原文地址 一.Docker 简介 Docker 两个主要部件: Docker: 开源的容器虚拟化平台 Docker Hub: 用于分享.管理 Docker 容器的 Docker SaaS 平台 --  ...

  9. 导出本地和远程SVN项目, Export remote SVN repository

    在有服务器控制权的情况下, 源服务器上 sudo svnadmin dump ironbank/ > ~/ironbank.svn.dump 在目的服务器上 sudo svnadmin crea ...

随机推荐

  1. Flask基础之返回值与form表单提交

    目录 1.Python 现阶段三大主流Web框架 Django Tornado Flask 对比 2.Flask的安装 3.Flask的第一个简单应用 4.Flask中的render_template ...

  2. Python系统运维常用库

    1.psutil是一个跨平台库(http://code.google.com/p/psutil/) 能够实现获取系统运行的进程和系统利用率(内存,CPU,磁盘,网络等),主要用于系统监控,分析和系统资 ...

  3. JAVA线程池的创建与使用

    为什么要用线程池? 我们都知道,每一次创建一个线程,JVM后面的工作包括:为线程建立虚拟机栈.本地方法栈.程序计数器的内存空间(下图可看出),所以线程过多容易导致内存空间溢出.同时,当频繁的创建和销毁 ...

  4. C语言结构体变量字节对齐问题总结

    结构体字节对齐 在用sizeof运算符求算某结构体所占空间时,并不是简单地将结构体中所有元素各自占的空间相加,这里涉及到内存字节对齐的问题.从理论上讲,对于任何 变量的访问都可以从任何地址开始访问,但 ...

  5. font-awesome图标显示问题解决方案

    font-awesome一个很强大的字体图标库.下载链接:http://fontawesome.dashgame.com/刚开始使用font-awesome的新手往往容易只引入一个css文件,这样就会 ...

  6. wordpress调用指定分类除外的置顶文章

    我们有时需要根据实际需要进行一些设置,比如wordpress调用指定分类除外的置顶文章,如何实现呢?随ytkah一起来看看吧,用如下代码插入到需要调取的位置 <div class="r ...

  7. hive中的日期转换函数

    1.unix时间戳转时间函数   语法: from_unixtime(bigintunixtime[, string format]) 返回值: string   说明: 转化UNIX时间戳(从197 ...

  8. docker 服务无法启动

    重装以后仍然不行,dockerd可以运行,但是systemctl start docker.service不行,后来在编辑一个文件时,提示没有空间可以保存,结果一查,发现服务器空间基本占满了, 通过 ...

  9. 【城市天气】使用Ajax发送和接受数据

    任务:利用中国天气网的公开接口,实现天气预报的查询功能 实验的功能要求如下: (1)当网页加载时,根据所给的 json 数据解析获得省(直辖市)的信息并显示在下拉列表框中供用户选择: (2)当用户选择 ...

  10. [RN] React Native 再按一次退出

    实现 React Native 再按一次退出 单页面: ... componentWillMount() { BackHandler.addEventListener('hardwareBackPre ...