How To Create a Sudo User on CentOS

轉(zhuǎn)自 https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart

簡單明了:

PostedMarch 29, 201681.3kviewsLINUX BASICSQUICKSTARTCENTOS

Introduction

Thesudocommand 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 CentOS, without having to modify your server'ssudoersfile. 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 therootuser.

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

Use the passwd command to update the new user's password.

passwd username

Set and confirm the new user's password at the prompt. A strong password is highly recommended!

Set password prompts:

Changing password for user username.New password:Retype new password:passwd: all authentication tokens updated successfully.

Use the usermod command to add the user to the wheel group.

usermod -aG wheel username

By default, on CentOS, members of the wheel 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.


Enable NOPASSWD for the?%wheel?group in?/etc/sudoers

$ sudo visudo

Then comment out this line:

## Allows people in group wheel to run all commands

# %wheel? ? ? ? ALL=(ALL)? ? ? ALL

And uncomment this line:

## Same thing without a password

%wheel? ALL=(ALL)? ? ? NOPASSWD: ALL

本地創(chuàng)建密鑰

ssh-keygen

拷貝公鑰

ssh-copy-id demo@SERVER_IP_ADDRESS

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末秋度,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子怎披,更是在濱河造成了極大的恐慌朦蕴,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,590評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件刊愚,死亡現(xiàn)場離奇詭異踊跟,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)鸥诽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評論 3 399
  • 文/潘曉璐 我一進(jìn)店門商玫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來箕憾,“玉大人,你說我怎么就攤上這事拳昌∠欤” “怎么了?”我有些...
    開封第一講書人閱讀 169,301評論 0 362
  • 文/不壞的土叔 我叫張陵炬藤,是天一觀的道長御铃。 經(jīng)常有香客問我,道長刻像,這世上最難降的妖魔是什么畅买? 我笑而不...
    開封第一講書人閱讀 60,078評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮细睡,結(jié)果婚禮上谷羞,老公的妹妹穿的比我還像新娘。我一直安慰自己溜徙,他們只是感情好湃缎,可當(dāng)我...
    茶點故事閱讀 69,082評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蠢壹,像睡著了一般嗓违。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上图贸,一...
    開封第一講書人閱讀 52,682評論 1 312
  • 那天蹂季,我揣著相機(jī)與錄音,去河邊找鬼疏日。 笑死偿洁,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的沟优。 我是一名探鬼主播涕滋,決...
    沈念sama閱讀 41,155評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼挠阁!你這毒婦竟也來了宾肺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,098評論 0 277
  • 序言:老撾萬榮一對情侶失蹤侵俗,失蹤者是張志新(化名)和其女友劉穎锨用,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體隘谣,經(jīng)...
    沈念sama閱讀 46,638評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡增拥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,701評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片跪者。...
    茶點故事閱讀 40,852評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖熄求,靈堂內(nèi)的尸體忽然破棺而出渣玲,到底是詐尸還是另有隱情,我是刑警寧澤弟晚,帶...
    沈念sama閱讀 36,520評論 5 351
  • 正文 年R本政府宣布忘衍,位于F島的核電站,受9級特大地震影響卿城,放射性物質(zhì)發(fā)生泄漏枚钓。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,181評論 3 335
  • 文/蒙蒙 一瑟押、第九天 我趴在偏房一處隱蔽的房頂上張望搀捷。 院中可真熱鬧,春花似錦多望、人聲如沸嫩舟。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽家厌。三九已至,卻和暖如春椎工,著一層夾襖步出監(jiān)牢的瞬間饭于,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評論 1 274
  • 我被黑心中介騙來泰國打工维蒙, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留掰吕,地道東北人。 一個月前我還...
    沈念sama閱讀 49,279評論 3 379
  • 正文 我出身青樓木西,卻偏偏與公主長得像畴栖,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子八千,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,851評論 2 361

推薦閱讀更多精彩內(nèi)容