我有 aws 实例密钥 .pem 文件,我将其保存在一个文件夹中
"home/debian/cs605\ data\ management/assignment6/mumbai\ instance\ keys"
密钥名称为 mumbai-instance-1.pem
我写了一个像这样的小 bash 脚本
!/bin/bash
AWS_KEY="home/debian/cs605\ data\ management/assignment6/mumbai\ instance\ keys"
ssh -v -i $AWS_KEY/mumbai-instance-1.pem
[email protected]
上述文件被保存在以下文件夹中,名为 mumbai
/home/debian/cs605 数据管理/assignment6
现在我尝试启动脚本,chmox +x mumbai
但出现错误
Warning: Identity file home/debian/cs605\ not accessible: No such file or directory.
OpenSSH_8.0p1 Ubuntu-6build1, OpenSSL 1.1.1c 28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
ssh: Could not resolve hostname data\\: Name or service not known
./mumbai: line 6: [email protected]: command not found
那么这个错误是什么?我该如何摆脱它?
更新 1
我尝试了答案中提到的方法
debian@osboxes:~/cs605 data management/assignment6$ ./mumbai
Warning: Identity file home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem not accessible: No such file or directory.
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
./mumbai: line 6: [email protected]: command not found
我检查了文件的权限
debian@osboxes:~/cs605 data management/assignment6/mumbai instance keys$ ls -l
total 8
-rwxr-xr-x 1 debian debian 1692 Mar 3 14:24 mumbai-instance-1.pem
-rwxrw-rw- 1 debian debian 1464 Mar 3 14:30 mumbai-instance-pvt.ppk
所以我不认为这应该是权限问题。
我在 AWS_KEY 中犯了一个错误,它应该是 /home
更新2
现在,在修复上述问题时,当我使用 AWS_KEY="/home/debian/cs605\ data\ management/assignment6/mumbai\ instance\ keys" 执行上述脚本时,出现以下问题:
debian@osboxes:~/cs605 data management/assignment6$ ./mumbai
OpenSSH_8.0p1 Ubuntu-6build1, OpenSSL 1.1.1c 28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-xx-xxx-xx-xxx.ap-south-1.compute.amazonaws.com [xx-xxx-xx-xxx] port 22.
debug1: Connection established.
debug1: identity file /home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem type -1
debug1: identity file /home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0p1 Ubuntu-6build1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 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
debug1: Authenticating to ec2-xx-xxx-xx-xxx.ap-south-1.compute.amazonaws.com:22 as 'ec2-user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:q5biO+y+QovuhX7TUfVShKOh7nQ/TaVUPhs8YI8EJOs
The authenticity of host 'ec2-xx-xxx-xx-xxx.ap-south-1.compute.amazonaws.com (xx-xxx-xx-xxx)' can't be established.
ECDSA key fingerprint is SHA256:q5biO+y+QovuhX7TUfVShKOh7nQ/TaVUPhs8YI8EJOs.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-xx-xxx-xx-xxx.ap-south-1.compute.amazonaws.com,xx-xxx-xx-xxx' (ECDSA) to the list of known hosts.
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: debian@osboxes RSA SHA256:iFf3gBtMBnZsrEYwqUEZBanwk9vj6/nf64NfpGerACU agent
debug1: Will attempt key: /home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1001)
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1001)
debug1: Next authentication method: publickey
debug1: Offering public key: debian@osboxes RSA SHA256:iFf3gBtMBnZsrEYwqUEZBanwk9vj6/nf64NfpGerACU agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Trying private key: /home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0755 for '/home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/debian/cs605 data management/assignment6/mumbai instance keys/mumbai-instance-1.pem": bad permissions
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
好的,我已修复它,密钥文件应具有 700 权限,而 750 或 755 是不可接受的。
答案1
这是因为您的路径中有空格,在这种情况下您必须使用引号。
尝试一下这个方法:
#!/bin/bash
AWS_KEY="/home/debian/cs605 data management/assignment6/mumbai instance keys"
ssh -v -i "$AWS_KEY"/mumbai-instance-1.pem
[email protected]
只需删除变量中的多余斜杠$AWS_KEY
并""
在使用时使用即可。