如何使用指令使用 ftp 將檔案從機器 A 複製到機器 B

如何使用指令使用 ftp 將檔案從機器 A 複製到機器 B

我想使用命令將檔案從來源電腦 A 複製到目標電腦 B,並希望使用 ftp。

我試過這個

scp /home/varun/Desktop/Test.java username_for_target_machine@ip_address_of_target_machine:/home/Desktop/

The authenticity of host 'ip_address_of_target_machine (ip_address_of_target_machine)' can't be established.
RSA key fingerprint is 4a:49:cc:9d:ab:f6:ec:4f:b2:0b:63:ef:8f:b8:76:76.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ip_address_of_target_machine' (RSA) to the list of known hosts.
qaserve@ip_address_of_target_machine's password: 

當我為目標機器提供密碼時

Permission denied, please try again.

我嘗試了多次,但得到了相同的輸出。

  1. 我哪裡出錯了?
  2. 如何在命令中給出使用者名稱和密碼,以便它不會詢問密碼?

更新:1

我嘗試使用 ssh。以下是我遵循的步驟。

1. 驗證本機和遠端主機是否正在執行 openSSH

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013

2. 使用 ssh-keygen 在本機上產生金鑰對

Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
31:3a:5d:dc:bc:81:81:71:be:31:2b:11:b8:e8:39:a0 jsmith@local-host

3. 在遠端主機上安裝公鑰。

[remote-host]$ vi ~/.ssh/authorized_keys 
ssh-rsa ABIwAAAQEAzRPh9rWfjZ1+7Q369zsBEa7wS1RxzWR jsmith@local-host

4. 為遠端主機上的 .ssh 目錄授予適當的權限。

[remote-host]$ chmod 755 ~/.ssh
[remote-host]$ chmod 644 ~/.ssh/authorized_keys

5. 從本機使用SSH密鑰認證登入遠端主機,驗證是否正常運作。

[local-host]$ ssh -l jsmith remote-host

當我運行上面的命令時,我得到:

ssh: connect to host remote-host port 22: Connection timed out

當我打字時

ssh -l ipaddress_of_remote-host remote-host

它要求輸入密碼:當我提供密碼時,它會連接到遠端主機。

為什麼我在遠端主機上註冊公鑰後又要求輸入密碼?

更新2: 抱歉弄亂了。

  1. 我想使用任何協議將文件從來源複製到目標。更改權限

  2. [遠端主機]$ chmod 700 ~/.ssh [遠端主機]$ chmod 600 ~/.ssh/authorized_key

答案1

  1. 您可能沒有遠端伺服器上 /home/Desktop 的權限,您可能想要嘗試 /home/username_for_target_machine/Desktop
  2. 不,我不這麼認為。但你可以穀歌搜尋“ssh公鑰認證”

答案2

你在這裡混淆了各種事情。首先,這一切都與 ftp 無關。你正在使用scp,而不是ftp。為什麼你提到ftp?然後,您似乎嘗試使用 IP 作為用戶名(-l給出要連接的用戶名)來連接到主機。另外,該檔案的權限是錯誤的authorized_keys,您需要600700,而不是644755。最後,無論如何,這確實不是複製金鑰的好方法,這就是目的ssh-copy-id

那麼,讓我們從頭開始嘗試吧。步驟 1 和 2 都可以,現在執行下列操作:

  1. 刪除您新增至遠端檔案的條目authorized_keys

  2. 修復遠端主機上的權限:

    [remote-host]$ chmod 700 ~/.ssh/
    [remote-host]$ chmod 600 ~/.ssh/authorised_keys
    
  3. 從本機主機,將密鑰複製到遠端:

    [local-host]$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@ipaddress_of_remote-host
    
  4. 嘗試再次登入

    [local-host]$ ssh jsmith@ipaddress_of_remote-host
    
  5. 主機似乎沒有正確地將其名稱匯出到網路。要快速修復,請運行:

    [本機]$ echo "ipaddress_of_remote-host 主機名稱" | sudo tee -a /etc/hosts sudo tee -a /etc/hosts

    這會將主機名稱儲存為其 IP 的別名。現在,您應該能夠連接到ssh user@hostname.

答案3

我認為您尚未配置 FTP,因為它要求輸入密碼,因此只需檢查此連結:

1)http://www.mpipks-dresden.mpg.de/~mueller/docs/suse10.2/html/opensuse-manual_en/manual/sec.filetrans.copy.html

若要設定 FTP 伺服器,請執行下列操作:

**Prepare the FTP server:**

    Install the vsftp package.

    Open a shell, login as root and save a backup copy of /etc/vsftpd.conf:

    cp /etc/vsftpd.conf /etc/vsftpd.conf.bak

    Create an access point for anonymous FTP

    mkdir ~ftp/incoming
    chown -R ftp:ftp ~ftp/incoming

Replace the configuration files depending on the scenario you prefer (refer to the manual page of vsftpd.conf for advanced configuration options):

Allowing Anonymous Read and Write Access

    #
    listen=YES

    # Enable anonymous access to FTP server
    anonymous_enable=YES

    #
    local_enable=YES
    # Enable write access
    write_enable=YES
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES
    dirmessage_enable=YES
    # Write log file 
    xferlog_enable=YES
    connect_from_port_20=YES
    chown_uploads=YES
    chown_username=ftp
    ftpd_banner=Welcome to FTP service.
    anon_root=/srv/ftp

Grant Restricted Permissions to FTP Users (Home Only)

    chroot_local_users=YES

Restart the FTP server:

rcvsftp start

在客戶端輸入URL即可ftp://主機在您的瀏覽器或 FTP 用戶端中。將 HOST 替換為伺服器的主機名稱或 IP 位址。有許多圖形使用者介面適合瀏覽 FTP 伺服器的內容。要取得它們的列表,只需在 YaST 套件管理器的搜尋提示字元下輸入 FTP 即可。

相關內容