1

I have aws instance key .pem file I saved that in a folder

"home/debian/cs605\ data\ management/assignment6/mumbai\ instance\ keys"

the key name is mumbai-instance-1.pem

I wrote a small bash script like this

!/bin/bash

AWS_KEY="home/debian/cs605\ data\ management/assignment6/mumbai\ instance\ keys"

ssh -v -i $AWS_KEY/mumbai-instance-1.pem
ec2-user@ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com

the above file was saved named mumbai in following folder

/home/debian/cs605 data management/assignment6

now I try to launch the script after chmox +x mumbai but I am getting error

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: ec2-user@ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com: command not found

so what is this error and how can I get rid of this.

update 1
I tried the method mentioned in answer

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: ec2-user@ec2-xx-xxx-xx-xx.ap-south-1.compute.amazonaws.com: command not found

I checked the permissions of file

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

so I don't think this should be a permissions issue.

I did a mistake above in AWS_KEY it should be /home

update2

Now while fixing the above issues I get following when I execute the above script with 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: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com 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.
ec2-user@ec2-.ap-south-1.compute.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

ok I fixed it the key file should have 700 permission and 750 or 755 is not acceptible.

2

it's because of white space in your path.

Try this way :

#!/bin/bash

AWS_KEY="/home/debian/cs605 data management/assignment6/mumbai instance keys"

ssh -v -i "$AWS_KEY"/mumbai-instance-1.pem
ec2-user@ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com

Just remove extra slashes in variable $AWS_KEY and use "" when you use it.

| improve this answer | |
  • ok I did what you tried now I am getting a permissions error not sure why is that coming. I updated the error in question, ok I got the error I did not added / at the beginning. Just dont want to do addiotional comment so updated here – political science Mar 4 at 18:09
  • oh i think we both forget about slash before "/home/..." instead "home/..." :)) – DamianK Mar 4 at 18:14
  • yes I updated the question slightly with update2 now ok now every thing is working perfectly fine. – political science Mar 4 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.