新建用户
useradd wang
passwd wang
usermod -s /bin/bash wang
usermod -d /home/wang wang
授权
chmod u+w /etc/sudoers
vim /etc/sudoers
root ALL=(ALL:ALL) ALL
wang ALL=(ALL:ALL) ALL
%sudo ALL=(ALL:ALL) ALL
tenguwang ALL=(ALL:ALL) NOPASSWD:ALL
---
chmod u-w /etc/sudoers
创建登陆用户
sudo useradd -r -m -s /bin/bash tenguwang
chmod 644 /home/safe/.ssh/id_rsa.pub
chmod 600 /home/safe/.ssh/id_rsa
shell
#!/usr/bin/bash
#
# TenguWang
read -p "请输入要创建的账户名称:" username
useradd -r -m -s /bin/bash ${username}
echo "用户${username}创建成功"
ls -al /home/${username}
read -p "请输入${username}密码:" passwd
echo "${username}:${passwd}" | sudo chpasswd
chmod +w /etc/sudoers
echo "${username} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
chmod -w /etc/sudoers
echo "${username}免密已设置完成"
echo "开始写入密钥文件"
mkdir /home/${username}/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC688q9OFg/AChEQiJJWQ80y6HCn2LDhNDlmNn9eR7r6ZsjICxF9K8q2S9QfUAH2O78Z2plFpoBqzk3N+JYLv4R9RkxlXJBZ2EHrWfpyjLIQsPb0Bh8CRjxw0BH2ZWeiBxuteIcAEedR61A4pPzsT5JBO+DUHrCXeYSIujuIAlIROF7W0HO3gSrhzZh8QsbWbEwTTn/fgnOtmkDPx3+gwrZmn4iXUdLBJs9rd/HVQTlhMfIXc6jn3xW0Ww3hTWdf8/+hL1tJum8B2VyywiiXmENbVHVH4U5uGuqOLXUUbigUbWaVIzyV9sbJg4SQtfUt+gVDhJ6eQVuA4r40ahhKU0PIy4fSEPn+oOWrHBeB1rFR1zrrwoVUoMvIA0sbjWfIKvJUrSwLS9KBSHplxGbY/xtpXNECoIYmHz9LQOrURjRJjrddFVdND2eKUpXdw1JUvRypjCKX50YcGl4kAmVBSVXG7LYZmA+EsC1JD24uavXlS454vI8uZPW6+GE3T1DaO0= TenGuWang" > /home/${username}/.ssh/authorized_keys
chown -R tenguwang.tenguwang /home/${username}/.ssh
echo "您用户${username}创建成功,密码:${passwd}"
useradd: cannot open /etc/passwd
解决办法
lsattr /etc/passwd
----i----------- /etc/passwd
# 去除i属性
chattr -i /etc/passwd
Cento7创建大于1000的用户密钥无法登录
usermod -u 555 tenguwang
groupmod -g 555 tenguwang
[root@tenguwang ~]# usermod -u 555 tenguwang
usermod: user tenguwang is currently used by process 21843
kill -9 `lsof -u tenguwang` # 直接杀掉
在Linux系统中,1000以下的UID是系统保留的UID。随意修改系统上某些帐号的 UID 很可能会导致某些程序无法进行,甚至导致系统无法顺利运行。我们可以通过/usr/share/doc/setup-2.8.71/uidgid来查看具体对应关系,当然不同的版本路径可能不一样,可以用/usr/share/doc/setup*/uidgid来通配
[root@tenguwang ~]# cat /usr/share/doc/setup-2.8.71/uidgid
NAME UID GID HOME SHELL PACKAGES
root 0 0 /root /bin/bash setup
bin 1 1 /bin /sbin/nologin setup
daemon 2 2 /sbin /sbin/nologin setup
sys - 3 - - setup
adm 3 4 /var/adm /bin/bash setup
tty - 5 - - setup
disk - 6 - - setup
lp 4 7 /var/spool/lpd /sbin/nologin setup
mem - 8 - - setup
kmem - 9 - - setup
wheel - 10 - - setup
cdrom - 11 - - setup
sync 5 (0) /sbin /bin/sync setup
shutdown 6 (0) /sbin /sbin/shutdown setup
halt 7 (0) /sbin /sbin/halt setup
mail 8 12 /var/spool/mail /sbin/nologin setup
news 9 13 /var/spool/news /sbin/nologin setup
uucp 10 14 /var/spool/uucp /sbin/nologin uucp
operator 11 (0) /root /sbin/nologin setup
games 12 (100) /usr/games /sbin/nologin setup
gopher 13 30 /var/gopher /sbin/nologin -(not created by default)
ftp 14 50 /var/ftp /sbin/nologin setup
man - 15 - - setup
oprofile 16 16 /var/lib/oprofile /sbin/nologin oprofile
pkiuser 17 17 /usr/share/pki /sbin/nologin pki-ca,rhpki-ca
dialout - 18 - - setup
floppy - 19 - - setup
games - 20 - - setup
slocate - 21 - - slocate
utmp - 22 - - initscripts,libutempter
squid 23 23 /var/spool/squid /dev/null squid
pvm 24 24 /usr/share/pvm3 /bin/bash pvm
named 25 25 /var/named /bin/false bind
postgres 26 26 /var/lib/pgsql /bin/bash postgresql-server
mysql 27 27 /var/lib/mysql /bin/bash mysql
nscd 28 28 / /bin/false nscd
rpcuser 29 29 /var/lib/nfs /bin/false nfs-utils
console - 31 - - dev
rpc 32 32 / /bin/false portmap
amandabackup 33 (6) /var/lib/amanda /bin/false amanda
tape - 33 - - setup
netdump 34 34 /var/crash /bin/bash netdump-client, netdump-server
utempter - 35 - - libutempter
vdsm 36 - / /bin/bash kvm, vdsm
kvm - 36 - - kvm, vdsm, libvirt
rpm 37 37 /var/lib/rpm /bin/bash rpm
ntp 38 38 /etc/ntp /sbin/nologin ntp
video - 39 - - setup
dip - 40 - - ppp
mailman 41 41 /var/mailman /bin/false mailman
gdm 42 42 /var/gdm /bin/bash gdm
xfs 43 43 /etc/X11/fs /bin/false XFree86-xfs
pppusers - 44 - - linuxconf
popusers - 45 - - linuxconf
slipusers - 46 - - linuxconf
mailnull 47 47 /var/spool/mqueue /dev/null sendmail
apache 48 48 /var/www /bin/false apache
wnn 49 49 /home/wnn /bin/bash FreeWnn
smmsp 51 51 /var/spool/mqueue /dev/null sendmail
puppet 52 52 /var/lib/puppet /sbin/nologin puppet
tomcat 53 53 /var/lib/tomcat /sbin/nologin tomcat
lock - 54 - - lockdev
ldap 55 55 /var/lib/ldap /bin/false openldap-servers
frontpage 56 56 /var/www /bin/false mod_frontpage
nut 57 57 /var/lib/ups /bin/false nut
beagleindex 58 58 /var/cache/beagle /bin/false beagle
tss 59 59 - /sbin/nologin trousers
piranha 60 60 /etc/sysconfig/ha /dev/null piranha
prelude-manager 61 61 - /sbin/nologin prelude-manager
snortd 62 62 - /sbin/nologin snortd
audio - 63 - - setup
condor 64 64 /var/lib/condor /sbin/nologin condord
nslcd 65 (55) / /sbin/nologin nslcd
wine - 66 - - wine
pegasus 66 65 /var/lib/Pegasus /sbin/nologin tog-pegasus
webalizer 67 67 /var/www/html/usage /sbin/nologin webalizer
haldaemon 68 68 / /sbin/nologin hal
vcsa 69 69 - /sbin/nologin dev,MAKEDEV
avahi 70 70 /var/run/avahi-daemon /sbin/nologin avahi
realtime - 71 - - -
tcpdump 72 72 / /sbin/nologin tcpdump
privoxy 73 73 /etc/privoxy /bin/bash privoxy
sshd 74 74 /var/empty/sshd /sbin/nologin openssh-server
radvd 75 75 / /bin/false radvd
cyrus 76 (12) /var/imap /bin/bash cyrus-imapd
saslauth - 76 - - cyrus-imapd
arpwatch 77 77 /var/lib/arpwatch /sbin/nologin arpwatch
fax 78 78 /var/spool/fax /sbin/nologin mgetty
nocpulse 79 79 /etc/sysconfig/nocpulse /bin/bash nocpulse
desktop 80 80 - /sbin/nologin desktop-file-utils
dbus 81 81 / /sbin/nologin dbus
jonas 82 82 /var/lib/jonas /sbin/nologin jonas
clamav 83 83 /tmp /sbin/nologin clamav
screen - 84 - - screen
quaggavt - 85 - - quagga
sabayon 86 86 - /sbin/nologin sabayon
polkituser 87 87 / /sbin/nologin PolicyKit
wbpriv - 88 - - samba-common
postfix 89 89 /var/spool/postfix /bin/true postfix
postdrop - 90 - - postfix
majordomo 91 91 /usr/lib/majordomo /bin/bash majordomo
quagga 92 92 / /sbin/nologin quagga
exim 93 93 /var/spool/exim /sbin/nologin exim
distcache 94 94 / /sbin/nologin distcache
radiusd 95 95 / /bin/false freeradius
hsqldb 96 96 /var/lib/hsqldb /sbin/nologin hsqldb
dovecot 97 97 /usr/libexec/dovecot /sbin/nologin dovecot
ident 98 98 / /sbin/nologin ident
nobody 99 99 / /sbin/nologin setup
users - 100 - - setup
qemu 107 107 / /sbin/nologin libvirt
ovirt 108 108 / /sbin/nologin libvirt
rhevm 109 109 /home/rhevm /sbin/nologin vdsm-reg
jetty 110 110 /usr/share/jetty /sbin/nologin jetty
saned 111 111 / /sbin/nologin sane-backends
vhostmd 112 112 /usr/share/vhostmd /sbin/nologin vhostmd
usbmuxd 113 113 / /sbin/nologin usbmuxd
bacula 133 133 /var/spool/bacula /sbin/nologin bacula
cimsrvr 134 134 / /sbin/nologin tog-pegasus-libs
mock - 135 / - mock
ricci 140 140 /var/lib/ricci /sbin/nologin ricci
luci 141 141 /var/lib/luci /sbin/nologin luci
activemq 142 142 /usr/share/activemq /sbin/nologin activemq
stap-server 155 155 /var/lib/stap-server /sbin/nologin systemtap
stapusr - 156 / - systemtap-runtime
stapsys - 157 / - systemtap-runtime
stapdev - 158 / - systemtap-runtime
swift 160 160 /var/lib/swift /sbin/nologin openstack-swift
glance 161 161 /var/lib/glance /sbin/nologin openstack-glance
nova 162 162 /var/lib/nova /sbin/nologin openstack-nova
keystone 163 163 /var/lib/keystone /sbin/nologin openstack-keystone
quantum 164 164 /var/lib/quantum /sbin/nologin openstack-quantum
cinder 165 165 /var/lib/cinder /sbin/nologin openstack-cinder
ceilometer 166 166 /var/lib/ceilometer /sbin/nologin openstack-ceilometer
ceph 167 167 /var/lib/ceph /sbin/nologin ceph-common
avahi-autoipd 170 170 /var/lib/avahi-autoipd /sbin/nologin avahi
pulse 171 171 /var/run/pulse /sbin/nologin pulseaudio
rtkit 172 172 /proc /sbin/nologin rtkit
abrt 173 173 /etc/abrt /sbin/nologin abrt
retrace 174 174 /usr/share/retrace-server /sbin/nologin retrace-server
ovirtagent 175 175 / /sbin/nologin ovirt-guest-agent
ats 176 176 / /sbin/nologin trafficserver
dhcpd 177 177 / /sbin/nologin dhcp
myproxy 178 178 /var/lib/myproxy /sbin/nologin myproxy-server
sanlock 179 179 /var/run/sanlock /sbin/nologin sanlock
aeolus 180 180 /var/aeolus /sbin/nologin aeolus-configure
wallaby 181 181 /var/lib/wallaby /sbin/nologin wallaby
katello 182 182 /usr/share/katello /sbin/nologin katello-common
elasticsearch 183 183 /usr/share/java/elasticsearch /sbin/nologin elasticsearch
mongodb 184 184 /var/lib/mongodb /sbin/nologin mongodb
jboss 185 185 /var/lib/jbossas /sbin/nologin jbossas-core #was jboss-as and wildfly
jbosson-agent 186 - / /sbin/nologin jboss-on-agent
jbosson - 186 - - jboss-on-agent
heat 187 187 /var/lib/heat /sbin/nologin heat
haproxy 188 188 /var/lib/haproxy /sbin/nologin haproxy
hacluster 189 - / /sbin/nologin pacemaker
haclient - 189 - - pacemaker
systemd-journal - 190 - - systemd
systemd-journal-gateway 191 191 / /sbin/nologin systemd
#systemd-journal-gateway dynamic on new systems (may have different uid/gid)
systemd-network 192 192 / /sbin/nologin systemd
systemd-resolve 193 193 / /sbin/nologin systemd
gnats ? ? ? ? gnats, gnats-db
listar ? ? ? ? listar
nfsnobody 65534 65534 /var/lib/nfs /sbin/nologin nfs-utils
# Note: nfsnobody is 4294967294 on 64-bit platforms (-2)