https://blog.csdn.net/yangshangwei/article/details/53024203
SFTP免密码登录操作方法
1) 登陆服务端主机,在当前用户根目录执行(以RSA算法为例)
如下命令:
ssh-keygen –t rsa
屏幕显示内容均可直接以回车使用默认项,此时在$home/.ssh目录下生成I d_rsa私钥(private key)及id_rsa.pub公钥(public key)两个文件。
2) 将服务端的$home/.ssh/id_rsa.pub文件上传到客户端机的$home/.ssh目录下
通过scp命令传到 客户端
scp $home/.ssh/id_rsa.pub username@client_ip:$home/.ssh
在客户端机$home/.ssh目录下执行命令:
cat id_rsa.pub >> authorized_keys
原文还需要将服务端的$home/.ssh/id_rsa.pub
文件上传到客户端机的$home/.ssh
目录下,但我没有执行,也可以免密码登录sftp了。
[wangyou@fg01 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ftpserver/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): (空,直接回车)
Enter same passphrase again: (空,直接回车)
Your identification has been saved in /home/ftpserver/.ssh/id_rsa.
Your public key has been saved in /home/ftpserver/.ssh/id_rsa.pub.
The key fingerprint is:
6a:b7:f8:a1:09:83:e7:91:46:65:a4:89:38:f2:3e:35 wangyou@fg01
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| . . + |
|+ . o o |
|.o o |
| . E S |
| . + o . |
| + B o o |
| = = = o |
| . +.o |
+-----------------+
备份客户端的authorized_keys
[hadoop@jiexi5 ~]$ cd .ssh
[hadoop@jiexi5 .ssh]$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
[hadoop@jiexi5 .ssh]$ cp authorized_keys authorized_keys_bak20190326
[hadoop@jiexi5 .ssh]$ ls
authorized_keys authorized_keys_bak20190326 id_rsa id_rsa.pub known_hosts
[hadoop@jiexi5 .ssh]$ cp /home/hadoop/id_rsa.pub authorized_keys
[wangyou@fg01 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ftpserver/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): (空,直接回车)
Enter same passphrase again: (空,直接回车)
Your identification has been saved in /home/ftpserver/.ssh/id_rsa.
Your public key has been saved in /home/ftpserver/.ssh/id_rsa.pub.
The key fingerprint is:
6a:b7:f8:a1:09:83:e7:91:46:65:a4:89:38:f2:3e:35 wangyou@fg01
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| . . + |
|+ . o o |
|.o o |
| . E S |
| . + o . |
| + B o o |
| = = = o |
| . +.o |
+-----------------+
备份客户端的authorized_keys
[hadoop@jiexi5 ~]$ cd .ssh
[hadoop@jiexi5 .ssh]$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
[hadoop@jiexi5 .ssh]$ cp authorized_keys authorized_keys_bak20190326
[hadoop@jiexi5 .ssh]$ ls
authorized_keys authorized_keys_bak20190326 id_rsa id_rsa.pub known_hosts
[hadoop@jiexi5 .ssh]$ cp /home/hadoop/id_rsa.pub authorized_keys