SFTP免密码登录操作方法

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值