scp 到 google cloud-shell 失敗(ssh 有效)

scp 到 google cloud-shell 失敗(ssh 有效)

我正在嘗試使用 scp 將大檔案複製到雲端 shell。

使用這裡建議的命令所以答案

gcloud alpha cloud-shell scp \
  localhost:~/Sites/my-app/big_file cloudshell:~/big_file

但即使我可以看到它為伺服器添加了密鑰,它也會失敗Permission denied (publickey).

如果我做

gcloud alpha cloud-shell ssh

它登入伺服器就好了

答案1

事實證明,Google的呼叫scp省略了正確的用戶名。

解決方案 我成功上傳了

/usr/bin/scp -P 6000 -i /Users/me/.ssh/google_compute_engine -o \
  StrictHostKeyChecking=no ~/Sites/my-app/bigfile \ 
  [email protected]:~/big_file

如何解決這個問題

我能夠使用--verbosity debug標誌發現這一點

# gcloud alpha cloud-shell scp --verbosity debug localhost:~/Sites/my-app/big_file cloudshell:~/big_file
    DEBUG: Running [gcloud.alpha.cloud-shell.scp] with arguments: [(cloudshell|localhost):DEST: "cloudshell:~/big_file", (cloudshell|localhost):SRC:1: "['localhost:~/Sites/my-app/big_file']", --verbosity: "debug"]
    DEBUG: Running command [/usr/bin/scp -P 6000
      -i /Users/chrisjensen/.ssh/google_compute_engine
      -o StrictHostKeyChecking=no
      ~/Sites/my-app/big_file 35.185.184.136:~/big_file].
[...more debug info...]

^ 這是顯示已執行指令的行

然後我跑去ssh看看參數有沒有差異

gcloud alpha cloud-shell ssh --verbosity debug
DEBUG: Running [gcloud.alpha.cloud-shell.ssh] with arguments: [--verbosity: "debug"]
DEBUG: Running command [/usr/bin/ssh -t -p 6000
  -i /Users/chrisjensen/.ssh/google_compute_engine
  -o StrictHostKeyChecking=no [email protected]].
[...more debug info...]

^ 請注意,它在伺服器 IP 前面新增了使用者名稱。

然後我複製了 scp 命令並添加了我的用戶名,它發揮了作用。

希望這可以幫助其他試圖解決這個問題的人。

答案2

這應該在最新版本的 gcloud 中得到修復,您可以透過 runnign 取得該版本gcloud components update。感謝您嘗試阿爾法!

相關內容