linux新增用戶,然后配置密鑰驗證


建新用戶

adduser hadoop

用戶創建后切換用戶su hadoop

生成密鑰

切換后執行ssh-keygen -t rsa生成密鑰

[hadoop@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
79:0a:3d:04:3d:83:d5:24:a8:94:62:89:f3:b7:90:f8 hadoop@172.31.10.94
The key's randomart image is:
+--[ RSA 2048]----+
| . . ..=oo.      |
|o + o o.+..      |
| = + .  .o       |
|. + o  o .       |
| . o .. S .      |
|  E .  . +       |
|        .        |
|                 |
|                 |
+-----------------+

然后把id_rsa.pub的改名成authorized_keys. id_rsa.pub里的內容最后會有 hadoop@localhost,轉成authorized_keys的時候如果不能登錄,就把最后這節刪掉.
當有多個公鑰時,在authorized_keys里追加寫就行了.另外要保證authorized_keys的權限是600,.ssh的權限是700

chmod 600 authorized_keys
chmod 700 .ssh

也可以用xshell生成密鑰,然后將公鑰上傳到服務器,寫入authorized_keys里.

ssh命令登錄遠程機

ssh -i ~/.ssh/<private_key_file> <username>@ip


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM