Software engineering notes

Linux Account

顯示 account 權限

show grants for test@'%';

查詢所屬群組

$ id test
uid=1000(test) gid=1000(test) groups=1000(test),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(sambashare),115(lpadmin)

useradd adduser差別

useradd 只會建立帳號,沒有Home, password, 系統shell

新增 account

sudo adduser newuser
或
RUN useradd --create-home -s /bin/bash test

將帳號加上 sudo 權限

方法1

加入: 將帳號加入 sudo group

sudo usermod -a -G sudo test
或
sudo adduser test sudo

移除: 將帳號移除 sudo group

sudo gpasswd -d test sudo

方法2

加入: 手動新增帳號到 /etc/sudoers :

# User privilege specification
root    ALL=(ALL:ALL) ALL
test     ALL=(ALL:ALL) ALL

移除: 到 /etc/sudoers 刪除該筆帳號

刪除user

先退出group,再執行

sudo deluser my_account --remove-all-files

or

sudo userdel my_account
sudo rm -rf /home/my_account

List sudo account

執行

getent group sudo | cut -d: -f4

或者去 /etc/group 的 sudo 看

帳號相關資訊

/etc/passwd :

test:x:1000:1000:test,,,:/home/test:/bin/bash

切換 www-data 帳號

直接用 su 會跳出錯誤訊息

su www-data
This account is currently not available.

應該用

su -s /bin/bash www-data

無法 ssh www-data 帳號

直接 ssh 是不行的

ssh www-data@localhost -p
www-data@localhost's password:
This account is currently not available.

因為 www-data 是被設定在 /usr/sbin/nologin