ubuntu创建sudo 用户
The sudo
command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu, without having to modify your server's sudoers
file. If you want to configure sudo for an existing user, simply skip to step 3.
Steps to Create a New Sudo User
-
Log in to your server as the
root
user.- ssh root@server_ip_address
-
Use the
adduser
command to add a new user to your system.Be sure to replace username with the user that you want to create.
- adduser username
-
Set and confirm the new user's password at the prompt. A strong password is highly recommended!
Set password prompts:Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
-
Follow the prompts to set the new user's information. It is fine to accept the defaults to leave all of this information blank.
User information prompts: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]
-
Use the
usermod
command to add the user to thesudo
group.- usermod -aG sudo username
By default, on Ubuntu, members of the
sudo
group have sudo privileges. -
Test sudo access on new user account
-
Use the
su
command to switch to the new user account.- su - username
-
As the new user, verify that you can use sudo by prepending "sudo" to the command that you want to run with superuser privileges.
- sudo command_to_run
-
For example, you can list the contents of the
/root
directory, which is normally only accessible to the root user.- sudo ls -la /root
-
The first time you use
sudo
in a session, you will be prompted for the password of the user account. Enter the password to proceed.Output:[sudo] password for username:
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2017-08-22 PostgreSQL sum typecasting as a bigint
2017-08-22 Using KafkaBolt to write to a kafka topic
2017-08-22 How to pass external configuration properties to storm topology?
2016-08-22 elasticSearch indices VS type
2016-08-22 一个不错的简历制作网站
2016-08-22 php active-record 设计模式