Linux相關小技巧《三》

需求:

前一段時間有收到這樣的一個關于linux用戶的權限相關的需求,在centos上給用戶創建一個用SSH的密鑰訪問服務器,另給該用戶添加到root權限組。記錄下了步驟,分享給大家。

步驟:

添加root用戶組:

groupadd ams

給用戶組添加root權限,且切換root不需要輸入root密碼,權限高,請注意

$ visudo  
## 添加了這一行 %ams    ALL=(ALL)       NOPASSWD: ALL## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem## Command Aliases
## These are groups of related commands...## Networking
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool## Installation and management of software
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum## Services## Updating the locate database
# Cmnd_Alias LOCATE = /usr/bin/updatedb## Storage
# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount## Delegating permissions
# Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp## Processes
# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall## Drivers
# Cmnd_Alias DRIVERS = /sbin/modprobe# Defaults specification#
# Refuse to run if unable to disable echo on the tty.
#
Defaults   !visiblepw#
# Preserving HOME has security implications since many programs
# use it when searching for configuration files. Note that HOME
# is already set when the the env_reset option is enabled, so
# this option is only effective for configurations where either
# env_reset is disabled or HOME is present in the env_keep list.
#
Defaults    always_set_home
Defaults    match_group_by_gid# Prior to version 1.8.15, groups listed in sudoers that were not
# found in the system group database were passed to the group
# plugin, if any. Starting with 1.8.15, only groups of the form
# %:group are resolved via the group plugin by default.
# We enable always_query_group_plugin to restore old behavior.
# Disable this option for new behavior.
Defaults    always_query_group_pluginDefaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults   env_keep += "HOME"Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
%ams    ALL=(ALL)       NOPASSWD: ALL## Allows members of the users group to mount and unmount the
## cdrom as root
# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d

添加用戶:

useradd <用戶名>

將用戶添加到root用戶組:

usermod -a -G ams <用戶名>

給用戶創建家目錄:

mkdir -p /home/<用戶名>/.ssh/

給用戶創建authorized_keys文件:

touch /home/<用戶名>/.ssh/authorized_keys

添加用戶的公鑰到authorized_keys中:

echo "ssh-rsa AAAAB3NzaC1yc2.....59AHv6osqY1ZuMrnl7Q== example@example.com" >> /home/<用戶名>/.ssh/authorized_keys

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/717606.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/717606.shtml
英文地址,請注明出處:http://en.pswp.cn/news/717606.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

跳躍游戲問題(算法村第十七關黃金挑戰)

跳躍游戲 55. 跳躍游戲 - 力扣&#xff08;LeetCode&#xff09; 給你一個非負整數數組 nums &#xff0c;你最初位于數組的 第一個下標 。數組中的每個元素代表你在該位置可以跳躍的最大長度。 判斷你是否能夠到達最后一個下標&#xff0c;如果可以&#xff0c;返回 true &…

人工智能-零基礎

機緣 擴充下知識棧&#xff0c;準備零基礎開始 人工智能零基礎 日常 日常水一下博客… 憧憬 努力成為一個會人工智能的程序員

軟考筆記--構件與軟件復用

構件也稱為組件&#xff08;component&#xff09;&#xff0c;是一個功能相對獨立的具有可復用價值的軟件單元。在面向對象的方法中&#xff0c;一個構件有一組對象組成&#xff0c;包含可一些協作的類的集成&#xff0c;它們協同工作來提供一種系統功能。可復用性是指系統和其…

138.樂理基礎-等音、等音程的意義

上一個內容&#xff1a;137.樂理基礎-協和音程、不協和音程 上一個內容里練習的答案&#xff1a; 等音、等音程的意義&#xff0c;首先在 19.音階 里寫了&#xff0c;一個調使用的音階應當是從主音快開始&#xff0c;以階梯狀的形式進行到主音結束&#xff0c;這樣才能明顯從樂…

在docker中運行 pip 報錯 Can‘t start new thread

原因源頭 stackoverflowhis is because the default seccomp profile of Docker 20.10.9 is not adjusted to support the clone() syscall wrapper of glibc 2.34 adopted in Ubuntu 21.10 and Fedora 35.由于docker 版本與最新版 python 容器沖突導致 解決方案 以下三種方…

b站小土堆pytorch學習記錄—— P16 神經網絡的基本骨架 nn.Module的使用

文章目錄 一、前置知識1.nn是什么2.nn如何使用 二、代碼 一、前置知識 1.nn是什么 在深度學習中&#xff0c;“nn” 通常是指神經網絡&#xff08;Neural Network&#xff09;的縮寫。神經網絡是一種由大量神經元&#xff08;neurons&#xff09;相互連接而成的模型&#xff…

【Python】成功解決TypeError: list indices must be integers or slices, not float

【Python】成功解決TypeError: list indices must be integers or slices, not float &#x1f308; 個人主頁&#xff1a;高斯小哥 &#x1f525; 高質量專欄&#xff1a;Matplotlib之旅&#xff1a;零基礎精通數據可視化、Python基礎【高質量合集】、PyTorch零基礎入門教程&…

vue 打包配置

vue打包配置記錄一下 publicPath: 打包的路徑 默認值&#xff1a;/&#xff08;根目錄&#xff09;&#xff1b; 任意路徑&#xff1a;""或者"./" (相對路徑) 參照&#xff1a;Vue CLI4.0 webpack配置屬性——publicPath_publicpath怎么寫相對路徑-CSDN…

springboot讀取自定義配置

springboot讀取自定義配置 application.yml自定義配置 my-app:ip1:#dmz1 ftp服務器ipAddress: 172.12.23.456port: 21username: adminpassword: adminip2:ipAddress: 172.12.23.457port: 21username: adminpassword: admin方式1&#xff0c;Value注解 Component public clas…

兩天學會微服務網關Gateway-Gateway工作原理

鋒哥原創的微服務網關Gateway視頻教程&#xff1a; Gateway微服務網關視頻教程&#xff08;無廢話版&#xff09;_嗶哩嗶哩_bilibiliGateway微服務網關視頻教程&#xff08;無廢話版&#xff09;共計17條視頻&#xff0c;包括&#xff1a;1_Gateway簡介、2_Gateway工作原理、3…

【網站項目】144校園二手物品交易平臺

&#x1f64a;作者簡介&#xff1a;擁有多年開發工作經驗&#xff0c;分享技術代碼幫助學生學習&#xff0c;獨立完成自己的項目或者畢業設計。 代碼可以私聊博主獲取。&#x1f339;贈送計算機畢業設計600個選題excel文件&#xff0c;幫助大學選題。贈送開題報告模板&#xff…

FRM模型十四:FRA估值

什么是FRA FRA&#xff08;Forward rate agrreement&#xff09;遠期利率協議&#xff0c;是一種場外衍生品。FRA在0時刻確定&#xff0c;在未來時刻進行交易的協議。例如FRA3,6表示雙方約定在3個月后以Rk的利率水平借款3個月。 應用場景&#xff1a;某公司未來3個月有融資需…

XWPFTemplate:基于Apache POI的Word文檔模板引擎

1. 前言 在Java領域中&#xff0c;處理Office文檔是一項常見的需求&#xff0c;尤其是對于生成報告、合同或其他結構化文檔。Apache POI是一個廣泛使用的庫&#xff0c;用于讀寫Microsoft Office格式文件&#xff08;包括Word、Excel等&#xff09;。然而&#xff0c;直接操作…

Kotlin 中編寫靜態方法的方式詳解

在 Kotlin 中&#xff0c;與 Java 不同&#xff0c;沒有 static 關鍵字來定義靜態方法。但是 Kotlin 提供了一種類似的機制來實現靜態方法。本文將介紹 Kotlin 中編寫靜態方法的兩種方式&#xff0c;并給出 Kotlin 和 Java 中的調用示例代碼。 方式一&#xff1a;使用頂層函數…

Vue 3 中的 $emit 函數是如何工作的

在 Vue.js 框架中&#xff0c;組件間的通信是一個核心概念。Vue 提供了多種方式來實現父子組件間的通信&#xff0c;其中 $emit 是子組件向父組件發送消息的一種常用手段。在 Vue 3 中&#xff0c;隨著 Composition API 的引入&#xff0c;$emit 的使用方式也發生了一些變化&am…

[HackMyVM] 靶場 Wave

kali:192.168.56.104 主機發現 arp-scan -l # arp-scan -l Interface: eth0, type: EN10MB, MAC: 00:0c:29:d2:e0:49, IPv4: 192.168.56.104 Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan) 192.168.56.1 0a:00:27:00:00:05 (Un…

OpenCV:開源計算機視覺的魔力之門

在當今這個信息爆炸的時代,圖像和視頻已經成為我們獲取和傳遞信息的主要方式之一。從社交媒體上的照片分享,到安防監控、自動駕駛等領域的圖像識別與處理,計算機視覺技術正日益改變著我們的生活。而在這場技術革命中,OpenCV(Open Source Computer Vision Library)這一開源…

Java JDBC JDBC事務管理 JDBC連接池(阿里巴巴Druid連接池、C3P0連接池) JDBC工具類

Java數據庫連接 Java DataBase Connectivity。JDBC 規范定義接口&#xff0c;具體的實現由各大數據庫廠商來實現。 JDBC可讓Java通過程序操作關系型數據庫&#xff0c;JDBC基于驅動程序實現與數據庫的連接與操作。 JDBC 是 Java 訪問數據庫的標準規范&#xff0c;真正怎么操作…

C++ 滑動窗口

例1 209. 長度最小的子數組 ①窗口大小不固定 ②求最小長度 -> ret INT_MAX ③數組內的值都大于0&#xff0c; 符合單調性&#xff08;sum nums[right] -> sum增大&#xff09; while里面符合條件&#xff0c;在里面更改ret 參考代碼 class Solution { public:i…

redis常見面試問題合集

什么是Redis&#xff1f; Redis是一個開源的、基于內存的數據結構存儲系統&#xff0c;它可以用作數據庫、緩存和消息隊列。Redis支持多種數據類型&#xff0c;包括字符串、列表、集合、有序集合和哈希表。 Redis支持的數據類型有哪些&#xff1f; Redis支持五種主要的數據類…