每天一個linux命令--ssh的host配置用戶名密碼


1、在終端輸入 cd ~/.ssh/

    vi config

    輸入服務器的用戶名和密碼

souche@kickseed:~/.ssh$ cat config 
# 這是跳板機的配置,給跳板機的 IP 起個別名: jump_machine, 用戶名: owen
Host feature
   HostName 172.III.III.III
   User XXX

2、生成 rsa 公鑰和私鑰: ssh-keygen -t rsa

     tip:如果ssh的目錄下面已經有公鑰,就不用生成了

souche@kickseed:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/souche/.ssh/id_rsa): 1HyKxJHtKz
1HyKxJHtKz already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in 1HyKxJHtKz.
Your public key has been saved in 1HyKxJHtKz.pub.
The key fingerprint is:
SHA256:PRQmfxrHWuWM5QgqTwd3OIsD8gPq70mf8JCzerVPzw8 souche@kickseed
The key's randomart image is:
+---[RSA 2048]----+
|        o =.. o  |
|    o .  Bo= O   |
|   . +..o.=oB +  |
|  .   o+o+.B     |
| .     .S.=      |
|  .  ..    .     |
|   .*. .. E      |
|   .oO.o o .     |
|  .++ +.. o..    |
+----[SHA256]-----+
souche@kickseed:~/.ssh$

 

 

3、 ssh-copy-id -i    密鑰文件   用戶別名@服務器別名

souche@kickseed:~/.ssh$ ssh-copy-id -i id_rsa.pub  souche@feature
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
souche@172.17.41.58's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'souche@feature'"
and check to make sure that only the key(s) you wanted were added.

souche@kickseed:~/.ssh$ ssh-copy-id -i id_rsa.pub  souche@eva

 


免責聲明!

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



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