AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[scp](unix)

Martin Hope
RobertIT
Asked: 2024-04-18 04:11:30 +0800 CST

scp 目标路径错误

  • 5

我正在将一个网站从远程服务器复制到另一个服务器,并且我有

SOURCE SERVER 
/var/www/vhosts/namesiteA.com
    /FolderA
    /FolderB

DESTINATION SERVER
/var/www/vhosts/namesiteB.com

  

运行以下 bash 后:

#!/bin/bash
SOURCE="[email protected]:/var/www/vhosts/namesiteA.com/"
DESTINATION="/var/www/vhosts/namesiteB.com/"
sshpass -p "<source_server_pass>" scp -p -r "$SOURCE" "$DESTINATION"

工作正常,但我期望:

DESTINATION SERVER
/var/www/vhosts/namesiteB.com
    /FolderA
    /FolderB 

instead I get:
/var/www/vhosts/namesiteB.com
    /namesiteA.com
        /FolderA
        /FolderB
scp
  • 1 个回答
  • 38 Views
Martin Hope
Marki
Asked: 2023-10-17 00:32:02 +0800 CST

SCP:无法在两个(远程)主机之间传输

  • 5

一种是使用密码验证,另一种则不是。

# scp -i ~user/.ssh/id_rsa_test01 user@test01:/tmp root@test02:/path/to/test01_bkp/
ssh: Could not resolve hostname test02: Name or service not known
lost connection
# host test02
test02.example.com has address 1.2.3.99

使用-vv:

Executing: /usr/bin/ssh -x -oClearAllForwardings=yes -n -v -v -i /home/user/.ssh/id_rsa_test01 -l user -- test01 scp -v /tmp root@test02:/path/to/test01_bkp/
OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug2: resolving "test01" port 22
debug2: ssh_connect_direct
debug1: Connecting to test01 [1.2.3.6] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa_test01 type 0
debug1: identity file /home/user/.ssh/id_rsa_test01-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2
debug1: match: OpenSSH_7.2 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to test01:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],umac-128-et[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: [email protected],[email protected],aes256-ctr,aes128-ctr
debug2: ciphers stoc: [email protected],[email protected],aes256-ctr,aes128-ctr
debug2: MACs ctos: [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
debug2: MACs stoc: [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16
debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 1510/3072
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:<stripped>
debug1: Host 'test01' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:12
debug2: bits set: 1510/3072
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /home/user/.ssh/id_rsa_test01 RSA SHA256:<stripped> explicit
debug2: pubkey_prepare: done
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/user/.ssh/id_rsa_test01 RSA SHA256:<stripped> explicit
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: /home/user/.ssh/id_rsa_test01 RSA SHA256:<stripped> explicit
debug1: Authentication succeeded (publickey).
Authenticated to test01 ([1.2.3.6]:22).
debug2: fd 4 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug1: Sending env LANG = POSIX
debug2: channel 0: request env confirm 0
debug1: Sending env LC_CTYPE = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug1: Sending command: scp -v /tmp root@test02:/path/to/test01_bkp/
debug2: channel 0: request exec confirm 1
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug2: channel 0: read<=0 rfd 4 len 0
debug2: channel 0: read failed
debug2: channel 0: chan_shutdown_read (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: rcvd ext data 107
Executing: program /usr/bin/ssh host test02, user root, command scp -v -t /path/to/test01_bkp/
debug2: channel 0: written 107 to efd 6
debug2: channel 0: rcvd ext data 49
OpenSSH_7.2p2, OpenSSL 1.0.2p-fips  14 Aug 2018
debug2: channel 0: written 49 to efd 6
debug2: channel 0: rcvd ext data 56
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: channel 0: written 56 to efd 6
debug2: channel 0: rcvd ext data 61
debug1: /etc/ssh/ssh_config line 25: Applying options for *
debug2: channel 0: written 61 to efd 6
debug2: channel 0: rcvd ext data 70
ssh: Could not resolve hostname test02: Name or service not known
debug2: channel 0: written 70 to efd 6
debug2: channel 0: rcvd ext data 16
lost connection
debug2: channel 0: written 16 to efd 6
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: chan_shutdown_write (i3 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3304, received 3784 bytes, in 0.1 seconds
Bytes per second: sent 29509.6, received 33796.7
debug1: Exit status 1

SLES 15SP2(运行 openssh-8.1p1)

scp
  • 1 个回答
  • 27 Views
Martin Hope
bafly
Asked: 2023-07-27 20:25:45 +0800 CST

使用 scp 将文件从当前目录复制到远程计算机的相应位置,而不定义完整路径

  • 5

有没有办法将文件或文件夹复制到与当前目录相同的地址的远程计算机,我在其中运行 spc 仅定义文件名,例如:

[user@machine current_location]$scp ./file_or_folder remote:$/
scp
  • 1 个回答
  • 15 Views
Martin Hope
IlludiumPu36
Asked: 2022-10-26 19:21:08 +0800 CST

从本地驱动器(不是 C:) 到远程服务器的 SCP

  • 5

试图将我本地 E: 驱动器上的文件 SCP 到远程服务器。我尝试了以下方法:

scp E:\Projects\new_server\ssl.conf user_id@host:/etc/httpd/conf.d/

但是得到:

ssh:无法解析主机名 e:名称或服务未知

除了 C: 之外,应该如何指定本地驱动器?

scp
  • 1 个回答
  • 28 Views
Martin Hope
HenDoNR
Asked: 2022-10-06 00:26:08 +0800 CST

如何通过scp命令将单个复制到多个文件中

  • 0

我想通过 scp 命令复制单个文件,以便将文件夹 ./a 传输到某个远程目录,如 {a1、a2、a3}。换句话说,我想要一个文件的多个副本。

这是一个例子:

scp -r a/ 'user@server:~/Data/{a1, a2, a3}'
scp: ambiguous target
scp
  • 1 个回答
  • 26 Views
Martin Hope
zpangwin
Asked: 2022-07-13 12:04:27 +0800 CST

ssh 在所有设备上工作,但来自某些设备的 scp 给出“连接已关闭”错误

  • 4

快速版本:

ssh在我的台式机和scp笔记本电脑上工作。从我的 android 手机上的 termuxssh可以工作,但scp不能。在这种情况下,我收到有关“连接已关闭”的错误。


扩展版

最初,当我问这个问题时,我在连接到我的 Fedora Linux 机器时,在我的 android 手机上从 termux 运行 scp 时遇到了这个问题。而且我一直很困惑,ssh所以我提供了很多调试信息。因为后来我了解到这个问题与 termux 完全无关,而与 OpenSSH 版本有关,所以我试图清理很多无关的信息转储并使其更易于访问,同时仍然保留相关的错误消息以更好地进行 seo 匹配.

设备:

  • 设备 A(计算机):运行 openssh.x86_64 8.7p1-3.fc35 的 Fedora 35
  • 设备 B(计算机):运行 openssh.x86_64 8.7p1-3.fc35 的 Fedora 35
  • device C (phone): android上的termux (我原来抓不到openssh版本,估计是v8.8或更高版本)

计算机 A 和 B 具有基本相同sshd_config的文件,所有 3 个基本相同的~/.ssh/config文件内容。

问题:

A->B、B->A、C->A 和 C->B 之间的 ssh 连接都工作正常。我对从任何一台计算机连接到我的手机都不感兴趣,并且从未在其上配置过 sshd,因此没有测试这种情况。

但是,对于通过 ssh 运行的 scp,我遇到了以下问题: A->B 和 B->A 工作,而 C->A 和 C->B 失败,出现以下错误:

$ scp -rp "[email protected]:/home/desktop-user/Pictures/test.jpg" .
scp: Connection closed
 

调试:

  • 大量验证 ssh 文件权限和所有权、~/.ssh/config设置等。没有明显问题。
  • 我(暂时)在 A 和 B 上禁用了 SELinux 和 firewalld,但仍然遇到同样的问题。
  • 根据这篇文章,我将自定义的 id_rsa(和 id_rsa.pub)文件名重命名为使用默认名称,并编辑了相应的~/.ssh/config定义。没变。
  • 我没有尝试(从 C 中)尝试从远程接收/拉取文件,而是尝试将文件推送/发送到远程。没变。
  • 从 C 开始,我确保所有软件包都是最新的。没变。
  • 从 C 中,我运行scp带有标志的命令-v以提供详细的调试信息。在编辑哈希等之后,我添加到pastebin。我看到的主要内容是密钥似乎已被接受,但最后一行表明“debug1:退出状态 127”。在线结果似乎表明scp主机上不存在......但就我而言,它是。所以还是没有变化。

主机的 sshd 配置

同样,A 和 B 具有基本相同的配置

# grep -Pv '^\s*(#|$)' /etc/ssh/sshd_config
Include /etc/ssh/sshd_config.d/*.conf
Port 22
Ciphers [email protected],aes256-ctr
LoginGraceTime 1m
PermitRootLogin no
MaxAuthTries 4
MaxSessions 6
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
UseDNS yes
AcceptEnv LANG LC_*
Subsystem   sftp    /usr/lib/openssh/sftp-server
Protocol 2
DenyUsers root docker-user
MACs [email protected],hmac-sha2-512,[email protected],hmac-sha2-256
KexAlgorithms diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
ssh scp
  • 1 个回答
  • 514 Views
Martin Hope
Zippy
Asked: 2022-06-28 16:32:05 +0800 CST

如何优化两个系统之间的文件传输并修剪文件

  • 0

我有计算机 1volts.json每秒将电压数据记录到一个文件中。

我的第二台计算机通过连接ssh并每 5 分钟抓取一次该文件。Splunk 为仪表板索引该文件。

以这种方式是scp有效的,如果是这样就可以了。接下来是如何管理文件并保持小而不增长到 2mb 可以说?是否有命令滚出较早的日志并保持最新的?

json 现在看起来像这样:

{
  "measuredatetime": "2022-06-27T18:00:10.915668",
  "voltage": 207.5,
  "current_A": 0.0,
  "power_W": 0.0,
  "energy_Wh": 2,
  "frequency_Hz": 60.0,
  "power_factor": 0.0,
  "alarm": 0
}
{
  "measuredatetime": "2022-06-27T18:00:11.991936",
  "voltage": 207.5,
  "current_A": 0.0,
  "power_W": 0.0,
  "energy_Wh": 2,
  "frequency_Hz": 59.9,
  "power_factor": 0.0,
  "alarm": 0
}
files scp
  • 1 个回答
  • 46 Views
Martin Hope
Jip Helsen
Asked: 2022-06-26 02:27:05 +0800 CST

使用 scp 复制时忽略文件

  • 2

使用命令时如何忽略某些文件scp?我在 Linux 服务器上有以下文件结构:

一切 >

  • 需要这个
  • 也需要这个
  • 不需要这个

我想得到NeedThis并NeedThisToo忽略DontNeedThis. 我不能只使用两个单独的scp,因为实际上有几百个文件。

我既不能移动也不能复制任何东西(这个问题的一部分,可以看作是一个设定条件)。有谁知道我的问题的解决方案?

scp
  • 1 个回答
  • 1027 Views
Martin Hope
pmor
Asked: 2022-06-03 06:31:41 +0800 CST

如何获得 scp 版本?

  • 4

如何获取scp版本?

已经尝试过:

$ scp --version
scp: unknown option -- -
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
           [-i identity_file] [-J destination] [-l limit]
           [-o ssh_option] [-P port] [-S program] source ... target

$ man scp | grep version
<nothing>

这是否意味着scp没有版本?

scp version
  • 1 个回答
  • 600 Views
Martin Hope
Nick M
Asked: 2021-12-19 04:39:46 +0800 CST

通过 ssh 将文件从一台机器复制到另一台机器时如何使用 sudo 权限

  • 2

好的,所以我已经知道如何将我机器中的文件复制到另一个文件,当我这样做时,(我试图将它复制到受 sudo 保护的目录)它说权限被拒绝。我不知道将 sudo 放在哪里,所以它不在我的机器中,但它不会妨碍目录。这是我通常输入的内容:

scp /Users/username/Documents/folder/folder/script.py [email protected]:/usr/local/bin
ssh scp
  • 1 个回答
  • 1982 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve