Linux用戶和用戶組,ssh免密登錄本地

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命令。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容