每天一个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

 

posted @ 2019-08-28 16:14  YOU_CAN  阅读(9313)  评论(0编辑  收藏  举报