Ubuntu 帳號停用與重新啟用

帳號停用

將帳號設定為昨天過期

sudo usermod -e $(date -d "yesterday" +"%Y-%m-%d") <user>

確認帳號期限

sudo chage -l <user>

封存家目錄

cd /home
sudo tar czvfp <name of archive>.tar.gz <username>

In addition, when doing a tar backup, it’s also good to add the following flags : p & (z/j)
-p will preserve the original file permissions
-z will compress using gzip (medium cpu usage, but less space)
-j will compress using bzip2 (lots of cpu, even less space)
-v verbose output (optional)

將封存檔移往 NFS 封存區

sudo rsync -avhP --remove-source-files <name of archive>.tar.gz /nfs/Backup/home_archive
# 或以下
sudo mv <name of archive>.tar.gz /nfs/Backup/home_archive

移除家目錄

sudo rm -rf /home/<user>

帳號重新啟用

重建家目錄

cd /home
sudo xzvf <name of archive>.tar.gz

重新啟用帳號

sudo usermod -e "" <user>

確認帳號期限

sudo chage -l <user>


參考資料

發表留言