通过SFTP访问其他设备文件示例(一键式)
组网需求
SSH提供了在一个传统不安全的网络环境中,服务器通过对客户端的认证及双向的数据加密,为网络终端访问提供了安全的服务。通过SFTP方式,客户端可以安全地连接到SSH服务器,进行文件的安全传输。
如图7-6所示,SSH服务器与客户端client001路由可达,此例中用华为设备作为SSH服务器。
要求:客户端一键式实现与服务器的安全连接并上传或下载服务器上的文件。
配置思路
采用如下思路配置通过SFTP一键式访问其他设备文件功能:
- 在服务器端生成本地密钥对及使能SFTP服务器功能,实现在服务器端和客户端进行安全地数据交互。
- 在SSH服务器上配置用户client001,使用password的认证方式登录SSH服务器,并配置SFTP访问目录。
- 在客户端使能SSH客户端首次登录功能。
- 用户client001以SFTP方式连接SSH服务器,实现上传或下载服务器上的文件。
操作步骤
- 在服务器端生成本地密钥对、指定服务器源接口及使能SFTP服务器功能。
<HUAWEI> system-view [~HUAWEI] sysname SSH Server [*HUAWEI] commit [~SSH Server] dsa local-key-pair create Info: The key name will be: SSH Server_Host_DSA Info: The key modulus can be any one of the following : 2048. Info: Key pair generation will take a short while. Info: Generating keys... Info: Succeeded in creating the DSA host keys. [*SSH Server] sftp server enable [*SSH Server] ssh server-source all-interface [*SSH Server] commit
- 在服务器端创建SSH用户client001,password认证,SFTP访问目录为flash:/。# 配置VTY用户界面属性。
[~SSH Server] user-interface vty 0 4 [~SSH Server-ui-vty0-4] authentication-mode aaa [*SSH Server-ui-vty0-4] protocol inbound all [*SSH Server-ui-vty0-4] user privilege level 3 [*SSH Server-ui-vty0-4] commit [~SSH Server-ui-vty0-4] quit
# 新建用户名为client001的SSH用户,且认证方式为password。[~SSH Server] ssh user client001 [*SSH Server] ssh user client001 authentication-type password [*SSH Server] ssh user client001 service-type sftp [*SSH Server] ssh user client001 sftp-directory flash: [*SSH Server] aaa [*SSH Server-aaa] local-user client001 password irreversible-cipher Helloworld@6789 [*SSH Server-aaa] local-user client001 service-type ssh [*SSH Server-aaa] local-user client001 level 3 [*SSH Server-aaa] commit
- SFTP客户端上使能SSH客户端首次登录功能。
<HUAWEI> system-view [~HUAWEI] sysname client001 [*HUAWEI] commit [~client001] ssh client first-time enable [*client001] commit
- 用户client001以SFTP方式连接SSH服务器,实现下载服务器上的文件abcd.txt。
[~client001] sftp client-transfile get host-ip 10.1.1.1 user client001 password Helloworld@6789 sourcefile abcd.txt
- 检查配置结果。
配置完成后,在SSH客户端上用户视图下执行dir命令可以查看到abcd.txt文件已经存放在flash:/路径下。
配置文件
SSH服务器上的配置文件
# sysname SSH Server # aaa local-user client001 password irreversible-cipher $1c$g8wLJ`LjL!$CyE(V{3qg5DdU:PM[6=6O$UF-.fQ,Q}>^)OBzgoU$ local-user client001 service-type ssh local-user client001 level 3 # sftp server enable ssh user client001 ssh user client001 authentication-type password ssh user client001 service-type sftp ssh user client001 sftp-directory flash: ssh server-source all-interface ssh authorization-type default aaa # user-interface vty 0 4 authentication-mode aaa user privilege level 3 # return
SSH客户端client001的配置文件
# sysname client001 # ssh client first-time enable # return