1,用戶和用戶組簡(jiǎn)介。
1)用戶信息。
用戶信息保存在/etc/passwd文件, 密碼信息 /etc/shadow
tomcat:x:501:501::/home/tomcat:/bin/bash
用戶名:密碼:Uid:Gid:用戶信息:home目錄:shell信息
2)組信息(/etc/group)
tomcat:x:501:
用戶組名:組密碼:GID:組內(nèi)帳號(hào)等
id zhanqi
groups zhanqi查看用戶屬于哪些組
3)更改用戶組
usermod -a -G admin mysql-G 修改用戶的附加組;-g修改用戶所屬的群組
2,添加用戶。
useradd tomcat
創(chuàng)建用戶時(shí),不指定其用戶所屬的工作組,自動(dòng)會(huì)生成一個(gè)與用戶名同名的工作組。
useradd tomcat == groupadd tomcat && useradd –g tomcat tomcat
image.png
passwd tomcat沒(méi)有設(shè)置密碼的用戶不能使用。
3,刪除用戶。
userdel tomcat
不會(huì)刪除/home/tomcat目錄
groupdel tomcat
4,
last -n 5 查看最近登錄的5個(gè)用戶
1)ssh登錄本地,ssh免密登錄
useradd test
usermod -a -G admin test
su test
ssh-keygen -t rsa
cat id_rsa.pub
vim authorized_keys
chmod 600 authorized_keys
chmod 600 id_rsa
chowm -R test:test authorized_keys
chowm -R test:test id_rsa
ssh test@127.0.0.1 -p 52722 -i /home/test/.ssh/id_rsa
5,ssh登錄遇到的一個(gè)問(wèn)題
1)使用tty終端登錄
sudo: sorry, you must have a tty to run sudo
終端(terminal)=tty=文本的輸入輸出環(huán)境
控制臺(tái)(console)=物理終端
shell=命令行解釋器
ssh tomcat@xxx.xxx.xxx.xxx -p 61935 -i /home/tomcat/.ssh/id_rsa "sudo ls -lah'報(bào)錯(cuò)異常信息sudo: sorry, you must have a tty to run sudo
2)Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
You have to run "ssh -t hostname sudo <cmd>".
#Defaults requiretty注釋掉這一行,來(lái)運(yùn)行不依賴tty也能執(zhí)行sudo命令。
