linux设置sudo权限

linux设置sudo权限,第1张

Linux用户配置sudo的工作过程如下:
1,当用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo的权限
2,确认用户具有可执行sudo的权限后,让用户输入用户自己的密码确认
3,若密码输入成功,则开始执行sudo后续的命令
4,root执行sudo时不需要输入密码(eudoers文件中有配置root ALL=(ALL) ALL这样一条规则)
5,若欲切换的身份与执行者的身份相同,也不需要输入密码
visudo使用vi打开/etc/sudoers文件,但是在保存退出时,visudo会检查内部语法,避免用户输入错误信息
visudo需要root权限
[Hadoop@localhost ~]$ visudo
visudo:/etc/sudoers:权限不够
visudo:/etc/sudoers:权限不够
使用visudo命令打开sudo配置文件
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password
## 该文件允许特定用户像root用户一样使用各种各样的命令,而不需要root用户的密码
##
## 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
## 该文件必须使用"visudo"命令编辑
## Host Aliases
## Groups of machines You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead
## 对于一组服务器,你可能会更喜欢使用主机名(可能是全域名的通配符)
## 、或IP地址,这时可以配置主机别名
# 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
## 指定一系列相互关联的命令(当然可以是一个)的别名,通过赋予该别名sudo权限,
## 可以通过sudo调用所有别名包含的命令,下面是一些示例
## 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 服务相关命令别名
# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
## 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
#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear
# You have to run "ssh -t hostname sudo <cmd>"
# 一些环境变量的相关配置,具体情况可见man soduers
Defaults requiretty
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC 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"
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)
## 下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享)
## Syntax(语法):
##
## user MACHINE=COMMANDS 用户 登录的主机=(可以变换的身份) 可以执行的命令
##
## The COMMANDS section may have other options added to it
## 命令部分可以附带一些其它的选项
##
## Allow root to run any commands anywhere
## 允许root用户执行任意路径下的任意命令
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more
## 允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE
, DRIVERS
## Allows people in group wheel to run all commands
## 允许wheel用户组中的用户执行所有命令
%wheel ALL=(ALL) ALL
## Same thing without a password
## 允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
## 允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
## 允许users用户组中的用户关闭localhost这台服务器
# %users localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoersd (the # here does not mean a comment)
## 读取放置在/etc/sudoersd/文件夹中的文件(此处的#不意味着这是一个声明)
#includedir /etc/sudoersd

下面给你介绍4种线程池:

1、newCachedThreadPool:

底层:返回ThreadPoolExecutor实例,corePoolSize为0;maximumPoolSize为IntegerMAX_VALUE;keepAliveTime为60L;unit为TimeUnitSECONDS;workQueue为SynchronousQueue(同步队列)

通俗:当有新任务到来,则插入到SynchronousQueue中,由于SynchronousQueue是同步队列,因此会在池中寻找可用线程来执行,若有可以线程则执行,若没有可用线程则创建一个线程来执行该任务;若池中线程空闲时间超过指定大小,则该线程会被销毁。

适用:执行很多短期异步的小程序或者负载较轻的服务器

2、newFixedThreadPool:


底层:返回ThreadPoolExecutor实例,接收参数为所设定线程数量nThread,corePoolSize为nThread,maximumPoolSize为nThread;keepAliveTime为0L(不限时);unit为:TimeUnitMILLISECONDS;WorkQueue为:new LinkedBlockingQueue<Runnable>() 无解阻塞队列

通俗:创建可容纳固定数量线程的池子,每隔线程的存活时间是无限的,当池子满了就不在添加线程了;如果池中的所有线程均在繁忙状态,对于新任务会进入阻塞队列中(无界的阻塞队列)

适用:执行长期的任务,性能好很多

3、newSingleThreadExecutor

底层:FinalizableDelegatedExecutorService包装的ThreadPoolExecutor实例,corePoolSize为1;maximumPoolSize为1;keepAliveTime为0L;unit为:TimeUnitMILLISECONDS;workQueue为:new LinkedBlockingQueue<Runnable>() 无解阻塞队列

通俗:创建只有一个线程的线程池,且线程的存活时间是无限的;当该线程正繁忙时,对于新任务会进入阻塞队列中(无界的阻塞队列)

适用:一个任务一个任务执行的场景

4、NewScheduledThreadPool:

底层:创建ScheduledThreadPoolExecutor实例,corePoolSize为传递来的参数,maximumPoolSize为IntegerMAX_VALUE;keepAliveTime为0;unit为:TimeUnitNANOSECONDS;workQueue为:new DelayedWorkQueue() 一个按超时时间升序排序的队列

通俗:创建一个固定大小的线程池,线程池内线程存活时间无限制,线程池可以支持定时及周期性任务执行,如果所有线程均处于繁忙状态,对于新任务会进入DelayedWorkQueue队列中,这是一种按照超时时间排序的队列结构

适用:周期性执行任务的场景

最后给你说一下线程池任务执行流程:

当线程池小于corePoolSize时,新提交任务将创建一个新线程执行任务,即使此时线程池中存在空闲线程。

当线程池达到corePoolSize时,新提交任务将被放入workQueue中,等待线程池中任务调度执行

当workQueue已满,且maximumPoolSize>corePoolSize时,新提交任务会创建新线程执行任务

当提交任务数超过maximumPoolSize时,新提交任务由RejectedExecutionHandler处理

当线程池中超过corePoolSize线程,空闲时间达到keepAliveTime时,关闭空闲线程

当设置allowCoreThreadTimeOut(true)时,线程池中corePoolSize线程空闲时间达到keepAliveTime也将关闭

ConnCloseThread中关闭连接的时候,不是立刻返回的。Connectionclose()会触发Connectioncommit(),而因为调用的存储过程中,存储过程起了自己的事务,connectioncommit()必须等到存储过程结束才能完成(这个是microsoft论坛上看到的)。如果所有connectionclose()都等到tx commit或rollback完成才执行的话,这个问题就不会出现了
从测试结果来看,凡是close connection耗时比execute statement短的,连接(物理连接)都会报出该问题。分析原因:通过weblogic datasource获取的connection并不是物理connection,而是由weblogic wrapped的connection。这些conection在被close后,并不会关闭物理连接,而只是将物理连接还池。我们对connection的所有 *** 作,最终都会被delegated到底层物理连接上,即commit(),rollback()最终都是在物理连接上执行。如果上面的connectionclose(),底层物理连接没有等到存储过程事务结束就返回的话,那么物理连接上应该还带有此次 *** 作的事务,而weblogic这边不会关系物理连接的情况,直接将连接放入connection pool供其它客户端使用。这时候如果设定了test on reserve的话,下次客户端从data source获取连接时,weblogic会检查这个物理连接,作一个select *** 作的,这个有问题的连接就会暴露出来,也就是上面的异常。这个问题如果使用driver manager来获取连接的话(如果每次都关闭的话),则不会出现,因为使用的物理连接每次都是不同的。还好,weblogic会帮忙重新创建有问题的连接。原因大概了解了,但这是谁的问题呢? 为什么connectionclose()不等存储过程的事务结束?
结论:一般而言,我们不建议通过JDBC调用存储过程的时候,在存储过程中定义事务,应该将tx的管理工作交给jdbc去做。 non-xa如此,xa亦如此,毕竟事务嵌套了以后,管理起来是个问题,完整性更是个问题。

使用组策略(最佳 *** 作)打开“组策略”。在“计算机配置”、“管理模板”、“Windows 组件”、“终端服务”中,双击“限制终端服务用户到一个远程会话”设置。单击“已启用”,然后单击“确定”。要点在将对组策略设置的更改应用到用户或计算机之前,应对任何更改进行全面测试。有关测试策略设置的详细信息,请参阅策略的结果集。注意To perform this procedure, you must be a member of the Administrators group on the local computer, or you must have been delegated the appropriate authority If the computer is joined to a domain, members of the Domain Admins group might be able to perform this procedure As a security best practice, consider using Run as to perform this procedure For more information, see Default local groups, Default groups, and Using Run as使用以上步骤配置本地组策略对象。要更改用于域或组织单位的策略,您必须以管理员身份登录到主域控制器。然后必须通过“Active Directory 用户和计算机”管理单元调用组策略。使用终端服务配置打开“终端服务配置”。在控制台树中,单击“服务器设置”。在详细信息窗格中,右键单击“限制每个用户使用一个会话”,然后单击“属性”。选中“限制每个用户使用一个会话”复选框,然后单击“确定”。注意To open Terminal Services Configuration, click Start, click Control Panel, double-click Administrative Tools, and then double-click Terminal Services Configuration注意To perform this procedure, you must be a member of the Administrators group on the local computer, or you must have been delegated the appropriate authority If the computer is joined to a domain, members of the Domain Admins group might be able to perform this procedure As a security best practice, consider using Run as to perform this procedure For more information, see Default local groups, Default groups, and Using Run as组策略将覆盖那些由终端服务配置工具设置的配置。通过指定在每个会话连接上启动不同的程序,用户总是能创建多个会话。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13442043.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-07
下一篇 2023-08-07

发表评论

登录后才能评论

评论列表(0条)

保存