-1
我虛心道歉,但是我在網絡中無處不在,我仍然無法做到這一點。這是迄今爲止發現的best指南。我也用this作爲指導。而且還是沒有用。如何在bash腳本中使用公鑰執行SCP
我需要執行一個腳本,該腳本會自動將本地文件發送到遠程機器。本地和遠程機器都是Linux。 編輯:腳本不應提示輸入用戶密碼 - 因此我應該使用公鑰。
什麼我迄今所做的:
編輯:執行的eval`SSH-agent`,然後SSH-添加,然後的ssh-copy-id命令
執行SSH-密鑰生成本地機器上,以產生id_rsa和 id_rsa.pub在的〜/ .ssh夾
- 應用於SSH-密鑰生成
- NO口令發送id_rsa.pub到遠程機器進入更名id_rsa其的〜/ .ssh夾
- 。酒館在遠程機器進入的authorized_keys(因爲它沒有原來存在)
腳本音響勒(本地機)
#!/bin/bash
scp -i ~/.ssh/id_rsa -o BatchMode=yes -v file.txt [email protected]:/home/meuser
輸出的SCP的詳細模式:
./scp_example.sh
Executing: program /usr/bin/ssh host webui01, user meuser2, command scp -v -t /home/meuser
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to remotemachine [###.###.###.###] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 504/505
debug1: identity file /home/meuser/.ssh/id_rsa type 1
debug1: loaded 1 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'remotemachine' is known and matches the RSA host key.
debug1: Found key in /home/meuser/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Next authentication method: publickey
debug1: Offering public key: /home/meuser/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
lost connection
希望有人可以擺脫光到這個。
感謝和問候。
嘗試使用rsync它將解決此問題:「我需要執行一個腳本,該腳本會自動將本地文件發送到遠程計算機。」 – Drako
嘗試使用'ssh-copy-id'安裝公鑰,而不是手動執行,如果可能的話,它會處理注意事項。還有(引用它的manpage):「[...]如果遠程sshd在其配置中設置了StrictModes,那麼用戶的home,〜/ .ssh'文件夾和〜/ .ssh/authorized_keys'文件需要手動禁用組可寫性,例如通過'chmod go-w ~~/.ssh〜/ .ssh/authorized_keys'「 –
@Drako對不起,我沒有提到我需要的是,在傳輸文件時,應該沒有「密碼」提示。我試過rsync,它幾乎和scp相似。感謝您的建議,雖然:) – thisNeil