Upload Jar file to AWS ec2 instance, Permission denied with scp

0

I have connected to the server using ssh ec2-user@MY_IP it was a success, and then I've installed java.

But when I tried to upload the JAR file using scp, I get this error:

ED25519 key fingerprint is SHA256:XXXXXXXXXXX.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?

And when I click yes, I get this error:

 Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Connection closed

I have added my public key as "Import key pair" that means I have no .pem file

What should I do? How can I upload file to the server, why I am getting this error, although the connection using ssh to the server works fine.

I connect using this

ssh ec2-user@MY_PUBLIC_IP

and then I tried to upload JAR using this

scp build/libs/app.jar ec2-user@MY_PUBLIC_IP:/home/ec2-user

then I get the error.

hasan
asked a year ago1436 views
2 Answers
1
Accepted Answer

I believe the issue is syntax. First, you don't need to ssh into the box to then run the SCP command. Make sure you are running this locally.

With the SCP command make sure the remote path ends with a /

scp build/libs/app.jar ec2-user@MY_PUBLIC_IP:/home/ec2-user/

That should do it.

profile picture
answered a year ago
  • This is right, sorry my bad, it works

0

If you are getting a "Permission denied" error while trying to upload a JAR file to an AWS EC2 instance using scp, it's likely that you don't have the required permissions to access the destination directory on the instance.

To resolve this issue, you can follow these steps:

Make sure that the destination directory on the EC2 instance exists and that you have the necessary permissions to access it. You can do this by logging in to the instance via SSH and checking the permissions of the directory using the ls -ld command.

Ensure that you have the correct syntax in your scp command. The syntax should be: scp -i /path/to/key.pem /path/to/local/file.jar user@ec2-instance-ip:/path/to/remote/directory/

If the issue persists, you can try changing the permissions of the destination directory using the chmod command: ** chmod 777 /path/to/remote/directory/**

This will give read, write, and execute permissions to all users.

Another solution is to use the sudo command to run scp with elevated permissions: ** sudo scp -i /path/to/key.pem /path/to/local/file.jar user@ec2-instance-ip:/path/to/remote/directory/**

Note: this requires that your user has sudo access on the EC2 instance.

By following these steps, you should be able to upload the JAR file to your EC2 instance using scp without encountering any permission issues.

profile picture
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions