转自: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. 如何预防SQL注入

    归纳一下,主要有以下几点: 1.永远不要信任用户的输入.对用户的输入进行校验,可以通过正则表达式,或限制长度:对单引号和 双"-"进行转换等. 2.永远不要使用动态拼装sql,可以 ...

  2. (七)Kubernetes Service资源

    Service概述 为什么要使用Service Kubernetes Pod是平凡的,由Deployment等控制器管理的Pod对象都是有生命周期的,它们会被创建,也会意外挂掉.虽然它们可以由控制器自 ...

  3. git提交时报错处理办法

    git提交时报错:Updates were rejected because the tip of your current branch is behind: 有如下几种解决方法: 1.使用强制pu ...

  4. scrum-master个人实践回顾总结

    个人回顾总结 一.开课提出问题 第一次博客地址:https://www.cnblogs.com/Slow-Walker/p/11513179.html 二.问题回答 2.1问题1:针对单元测试 怎么保 ...

  5. jmeter,badboy,jar包文件 常数吞吐量计时器?

    badboy录制脚本 1.按f2 红色开始录制 URL输入:https://www.so.com/ 2.搜索框输入zxw 回车键搜索 3.选中关键字(刮例如zxw软件——>tools——> ...

  6. HTTP1.0、HTTP1.1、HTTP2.0的关系和区别

    一.汇总对比 HTTP1.0 无状态.无连接HTTP1.1 持久连接请求管道化增加缓存处理(新的字段如cache-control)增加Host字段.支持断点传输等(把文件分成几部分)HTTP2.0 二 ...

  7. 编译lua固件NodeMcu 8266

    https://www.cnblogs.com/yangfengwu/p/10547024.html 因为我现在的Wifi的教程是lua语言编写的,但是有些功能需要自己编译lua固件才可以,这篇文章就 ...

  8. 单片机模块化程序: 单片机加入JSON是个不错的选择

    这节需要知道的知识点 https://www.cnblogs.com/yangfengwu/p/11685325.html 下载JSON文件: 链接:         https://sourcefo ...

  9. Eclipse中如何配置lombok

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_41441210/article/d ...

  10. hive基础知识一

    1. Hive是什么 1.1 hive的概念 Hive:由Facebook开源,用于解决海量(结构化日志)的数据统计. Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张表 ...