我正在使用 LFTP 来将 SFTP 服务器文件夹与本地文件夹镜像。
但目前我很高兴能够正确连接到 SFTP 服务器并列出内容......
我使用的是 Windows 7,并且从 NWGAT 下载了 LFTP 包(http://nwgat.ninja/lftp-for-windows/)。
我很清楚,我必须首先使用ssh
命令建立 sftp 连接:
ssh -v -a -x -vvv -o UserKnownHostsFile=/ssh/known_hosts -i /ssh/MyPrivateKey.ppk -p 22 [email protected]
文章的最后是该命令的输出。
如果我使用 WinSCP 和 ppk 文件,我可以毫无问题地连接。但ssh
在命令提示符下使用(ppk 不接受密码,pri 进行身份验证)我遇到了这个问题(使用 putty 和 ppk 文件时也会出现同样的问题 - 服务器拒绝启动 shell/命令)。
我的代码是否出了问题或者我遗漏了什么?
或者也应该在服务器端设置一些东西(例如:权限,某些不匹配的东西)?
这是代码和输出,感谢您的帮助。
ssh -v -a -x -vvv -o UserKnownHostsFile=/ssh/known_hosts -i /ssh/MyPrivateKey.pri -p 22 [email protected]
OpenSSH_6.6.1, OpenSSL 1.0.1i 6 Aug 2014
debug2: ssh_connect: needpriv 0
debug1: Connecting to sftp.domain.com [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/ssh/MyPrivateKey.pri" as a RSA1 public key
debug1: identity file /ssh/MyPrivateKey.pri type -1
debug1: identity file /ssh/MyPrivateKey.pri-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version SFTP_XXXXX
debug1: no match: SFTP_XXXXX
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "sftp.domain.com" fr
om file "/ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],ssh-
[email protected],ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-
sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hel
lman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],ssh-rsa-cert-v00@openssh
.com,ssh-rsa,[email protected],ecdsa-sha2-nistp384-cert-v
[email protected],[email protected],ssh-ed25519-cert-v01@ope
nssh.com,[email protected],[email protected],ecdsa-sha2-ni
stp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12
8,[email protected],[email protected],[email protected],ae
s128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndae
[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12
8,[email protected],[email protected],[email protected],ae
s128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndae
[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],um
[email protected],[email protected],[email protected],hma
[email protected],[email protected],hmac-sha1-96-etm@opens
sh.com,[email protected],hmac-md5,hmac-sha1,[email protected],umac-1
[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh
.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],um
[email protected],[email protected],[email protected],hma
[email protected],[email protected],hmac-sha1-96-etm@opens
sh.com,[email protected],hmac-md5,hmac-sha1,[email protected],umac-1
[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh
.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group1-sha1,diffie-hellman-group14-sha
1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
debug2: kex_parse_kexinit: [email protected],ssh-rsa
debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,aes128-cbc
debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,aes128-cbc
debug2: kex_parse_kexinit: hmac-sha512,hmac-sha2-512,hmac-sha256,hmac-sha2-256,h
mac-sha1
debug2: kex_parse_kexinit: hmac-sha512,hmac-sha2-512,hmac-sha256,hmac-sha2-256,h
mac-sha1
debug2: kex_parse_kexinit: zlib,none
debug2: kex_parse_kexinit: zlib,none
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: setup hmac-sha1
debug1: kex: server->client aes256-ctr hmac-sha1 none
debug2: mac_setup: setup hmac-sha1
debug1: kex: client->server aes256-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<8192<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 4119/8192
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 45:49:72:ff:5c:97:0b:ba:57:98:5a:2a:49:18:21:fa
debug3: load_hostkeys: loading entries for host "sftp.domain.com" fr
om file "/ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "XXX.XXX.XXX.XXX" from file "/ssh
/known_hosts"
debug3: load_hostkeys: found key type RSA in file /ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'sftp.domain.com' is known and matches the RSA host key
.
debug1: Found key in /ssh/known_hosts:1
debug2: bits set: 4092/8192
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /ssh/MyPrivateKey.pri (0x0), explicit
debug3: input_userauth_banner
****************************************
XXXXXXXXXXXXXXXXXXXXXXXXXXXX
****************************************
This system is for the use of authorized users only
****************************************debug1: Authentications that can continu
e: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /ssh/MyPrivateKey.pri
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/ssh/MyPrivateKey.pri':
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug3: sign_and_send_pubkey: RSA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
debug2: we sent a publickey packet, wait for reply
debug1: Authentication succeeded (publickey).
Authenticated to sftp.domain.com ([XXX.XXX.XXX.XXX]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 16384 rmax 35000
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel_input_status_confirm: type 100 id 0
shell request failed on channel 0
答案1
OpenSSH 工具集不理解.ppk
密钥文件格式。它使用自己的格式。正如 PuTTY(和 WinSCP)使用其格式(.ppk
),因此不理解 OpenSSH 格式。
您可以使用 PuTTYgen(来自 PuTTY 工具集)将密钥转换.ppk
为 OpenSSH 格式。
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter8.html#puttygen-conversions
答案2
这与 sftp 的行为相同(ssh 不知道 ppk 格式),您需要将 ppk 文件转换为 openssh 格式。
我使用此过程将我的 ppk 从 Windows(winscp 脚本)转换为 Linux(sftp 脚本)。
从Windows应用程序:
- 打开 puttygen,点击加载
- 选择你的 ppk 并根据提示输入你的密码
- 点击转换菜单 -> 导出 OpenSSH 密钥
- 选择一个新的文件名.key并点击保存
笔记:新的 ssh 密钥在转换过程中保留密码
要测试密钥,请先保护您的密钥文件:chmod 600 yournewsshkey.key
sftp -v -i yournewsshkey.key [email protected]
出现提示时,输入您的密码
干杯