Ubuntu設(shè)置key登錄 禁止root

  • 增加用戶
useradd yourname
  • 設(shè)置密碼
passwd yourname
  • 創(chuàng)建目錄
mkdir /home/yourname
  • 授權(quán)
chown yourname: /home/yourname
  • 設(shè)置key登錄
vim /etc/ssh/sshd_config
  • 禁止密碼驗證
PasswordAuthentication no
  • 啟用密鑰驗證
RSAAuthentication yes
PubkeyAuthentication yes
  • 禁止root用戶登錄
PermitRootLogin no
  • 指定公鑰數(shù)據(jù)庫文件
AuthorizedKeysFile .ssh/authorized_keys
  • 重啟sshd服務(wù)
service sshd restart
  • 可能會提示服務(wù)未注冊 使用
/etc/init.d/ssh restart
  • 設(shè)置yourname用戶為sudoers
  • 增加寫權(quán)限
chmod u+w /etc/sudoers
vim /etc/sudoers
  • 在 root ALL=(ALL) ALL 后面增加一行
yourname ALL=(ALL) ALL
  • 撤銷寫權(quán)限
chmod u-w /etc/sudoers
  • 切換用戶
su yourname
cd /home/yourname
  • 創(chuàng)建ssh目錄
mkdir .ssh
cd .ssh
  • 創(chuàng)建ssh key
ssh-keygen
  • 設(shè)置公鑰
cat id_dsa.pub >> authorized_keys
  • 下載私鑰 使用私鑰登錄
sz id_dsa
  • rz命令不存在
sudo apt-get update
sudo apt-get install lrzsz
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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