FastHandle is fast operation tools for infrastructure configurations and tests.
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
os:linux:user:index.html [2018/01/04 23:34] kurihara |
os:linux:user:index.html [2019/02/11 00:39] (current) kurihara |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| [[: | [[: | ||
| - | ====== User Management (user.py)===== | + | ====== |
| $FHHOME/ | $FHHOME/ | ||
| Line 7: | Line 7: | ||
| \\ | \\ | ||
| - | ===== Operation ===== | + | ===== Operation |
| + | ==== print list of possible commands | ||
| <sxh bash toolbar: | <sxh bash toolbar: | ||
| - | $ fab -l |grep user | + | $ fab -l |grep -F user. |
| + | user.check_group | ||
| + | user.check_user | ||
| + | user.chpasswd_devuser01_pro | ||
| + | user.chpasswd_devuser01_qa | ||
| + | user.chpasswd_devuser01_stg | ||
| + | user.chpasswd_devuser02_pro | ||
| + | user.chpasswd_devuser02_stg | ||
| + | user.chpasswd_devuser03_pro | ||
| + | user.chpasswd_root_pro | ||
| + | user.chpasswd_root_qa | ||
| + | user.chpasswd_root_stg | ||
| + | user.useradd_dev_all | ||
| + | user.useradd_devuser01 | ||
| + | user.useradd_devuser02 | ||
| + | user.useradd_opeuser01 | ||
| + | user.userdel_devuser01 | ||
| + | | ||
| + | </ | ||
| - | $ fab -H $H auth.pro | + | ==== Example ==== |
| + | |||
| + | <sxh bash toolbar: | ||
| + | $ fab -H $H user.check_user: | ||
| + | $ echo x.x.x.x | fab | ||
| </ | </ | ||
| + | ==== Fabric one-line Task Examples==== | ||
| <sxh bash toolbar: | <sxh bash toolbar: | ||
| $ H=test-server-1 | $ H=test-server-1 | ||
| - | $ fab -H $H auth.pro | + | $ fab -H $H -- hostname |
| + | |||
| + | $ fab -H $H -- id user01 | ||
| + | $ fab -H $H -- "cat /etc/passwd |grep user01" | ||
| + | $ fab -H $H -- grep user01 /etc/group | ||
| - | $ fab -H $H auth.pro | + | $ fab -H $H -- sudo gpasswd |
| - | $ fab -H $H auth.pro -- "cat /etc/passwd |grep user01" | + | $ fab -H $H -- sudo gpasswd -r user1 sudo # remove USER from GROUP |
| - | $ fab -H $H auth.pro | + | |
| </ | </ | ||
| Line 30: | Line 57: | ||
| ====How to Create Hash Password==== | ====How to Create Hash Password==== | ||
| <sxh python toolbar: | <sxh python toolbar: | ||
| - | # openssl passwd -1 ' | + | ~]# openssl passwd -1 ' |
| $1$0u444IQv$YSGCzz8mesPzCWwxHCxit. | $1$0u444IQv$YSGCzz8mesPzCWwxHCxit. | ||
| - | # echo ' | + | ~]# echo ' |
| - | # cat /etc/shadow |grep test1 | + | ~]# cat /etc/shadow |grep test1 |
| test1: | test1: | ||
| - | # exit | + | ~]# exit |
| - | $ su - user01 | + | ~]$ su - user01 |
| <- newpassword | <- newpassword | ||
| </ | </ | ||
| Line 47: | Line 74: | ||
| <sxh python toolbar: | <sxh python toolbar: | ||
| - | import sys | + | import sys, os |
| from fabric.api import * | from fabric.api import * | ||
| from fabric.contrib import files | from fabric.contrib import files | ||
| from fabric.utils import abort | from fabric.utils import abort | ||
| + | |||
| + | FHHOME=os.environ[" | ||
| # | # | ||
| Line 60: | Line 89: | ||
| @task | @task | ||
| def check_user(user): | def check_user(user): | ||
| - | """ | + | """ |
| res = run(" | res = run(" | ||
| if res.failed is True: | if res.failed is True: | ||
| Line 72: | Line 101: | ||
| @task | @task | ||
| def check_group(group): | def check_group(group): | ||
| - | """ | + | """ |
| - | res = run(" | + | res = run(" |
| if res.failed is True: | if res.failed is True: | ||
| puts(red(" | puts(red(" | ||
| Line 80: | Line 109: | ||
| # | # | ||
| - | # | + | # user.useradd |
| - | # useradd -u UID -g GROUP -G GROUP1, | + | # useradd |
| + | # -m : create the user's home directory | ||
| # | # | ||
| # | # | ||
| Line 99: | Line 129: | ||
| res = run(" | res = run(" | ||
| if res.failed is True: | if res.failed is True: | ||
| - | sudo(" | + | sudo(" |
| return | return | ||
| Line 106: | Line 136: | ||
| res = run(" | res = run(" | ||
| if res.failed is True: | if res.failed is True: | ||
| - | sudo(" | + | sudo(" |
| return | return | ||
| Line 118: | Line 148: | ||
| if res.succeeded is True: | if res.succeeded is True: | ||
| abort(" | abort(" | ||
| - | sudo(" | + | sudo(" |
| Line 133: | Line 162: | ||
| @task | @task | ||
| def chpasswd_root_pro(): | def chpasswd_root_pro(): | ||
| - | | + | ''' |
| + | | ||
| # user.chpasswd_root_stg | # user.chpasswd_root_stg | ||
| @task | @task | ||
| def chpasswd_root_stg(): | def chpasswd_root_stg(): | ||
| - | | + | ''' |
| + | | ||
| # user.chpasswd_root_qa | # user.chpasswd_root_qa | ||
| @task | @task | ||
| def chpasswd_root_qa(): | def chpasswd_root_qa(): | ||
| - | | + | ''' |
| + | | ||
| # | # | ||
| - | # chpasswd | + | # chpasswd |
| # | # | ||
| # user.chpasswd_devuser01_pro | # user.chpasswd_devuser01_pro | ||
| @task | @task | ||
| def chpasswd_devuser01_pro(): | def chpasswd_devuser01_pro(): | ||
| - | sudo(" | + | sudo(" |
| # user.chpasswd_devuser01_stg | # user.chpasswd_devuser01_stg | ||
| @task | @task | ||
| def chpasswd_devuser01_stg(): | def chpasswd_devuser01_stg(): | ||
| - | sudo(" | + | sudo(" |
| # user.chpasswd_devuser01_qa | # user.chpasswd_devuser01_qa | ||
| @task | @task | ||
| def chpasswd_devuser01_qa(): | def chpasswd_devuser01_qa(): | ||
| - | sudo(" | + | sudo(" |
| + | |||
| + | # | ||
| + | # chpasswd devuser02 | ||
| + | # | ||
| # user.chpasswd_devuser02_pro | # user.chpasswd_devuser02_pro | ||
| @task | @task | ||
| def chpasswd_devuser02_pro(): | def chpasswd_devuser02_pro(): | ||
| - | sudo(" | + | sudo(" |
| + | |||
| + | # user.chpasswd_devuser02_stg | ||
| + | @task | ||
| + | def chpasswd_devuser02_stg(): | ||
| + | sudo(" | ||
| + | |||
| + | # | ||
| + | # chpasswd devuser03 | ||
| + | # | ||
| # user.chpasswd_devuser03_pro | # user.chpasswd_devuser03_pro | ||
| @task | @task | ||
| def chpasswd_devuser03_pro(): | def chpasswd_devuser03_pro(): | ||
| - | sudo(" | + | sudo(" |
| + | |||
| # | # | ||
| - | #userdel | + | # userdel |
| # -r, --remove : Files in the user's home directory will be removed | # -r, --remove : Files in the user's home directory will be removed | ||
| # | # | ||
| Line 192: | Line 239: | ||
| sudo(" | sudo(" | ||
| return | return | ||
| - | |||
| - | # | ||
| - | # etc | ||
| - | # | ||
My Sites
SNS
Copyright (c) 2025 FastHandle - IT Operations Examples All Rights Reserved.