SCP Permission denied (publickey). on EC2 only when using -r flag on directories

前端 未结 5 742
轻奢々
轻奢々 2021-01-30 10:41

scp -r /Applications/XAMPP/htdocs/keypairfile.pem uploads ec2-user@publicdns:/var/www/html

where uploads is a directory returns Permission denied (publicke

相关标签:
5条回答
  • 2021-01-30 10:50

    transferring file from local to remote host

    scp -i (path of your key) (path for your file to be transferred) (username@ip):(path where file to be copied)

    e.g scp -i aws.pem /home/user1/Desktop/testFile   ec2-user@someipAddress:/home/ec2-user/
    

    P.S. - ec2-user@someipAddress of this ip address should have access to the destination folder in my case /home/ec2-user/

    0 讨论(0)
  • 2021-01-30 10:50

    I was initially running:

    sudo scp
    

    Once I ran just scp, without sudo, it copied everything fine:

    scp
    

    It seems to me that sudo scp command wasn't reading my current user's SSH public key at ~/.ssh/id_rsa.pub.

    0 讨论(0)
  • 2021-01-30 10:53

    If you want to upload the file /Applications/XAMPP/htdocs/keypairfile.pem to ec2-user@publicdns:/var/www/html, you can simply do:

    scp -Cr /Applications/XAMPP/htdocs/keypairfile.pem/uploads/ ec2-user@publicdns:/var/www/html/

    Where:

    • -C - Compress data
    • -r - Recursive
    0 讨论(0)
  • 2021-01-30 10:56

    The -i flag specifies the private key (.pem file) to use. If you don't specify that flag (as in your first command) it will use your default ssh key (usually under ~/.ssh/).

    So in your first command, you are actually asking scp to upload the .pem file itself using your default ssh key. I don't think that is what you want.

    Try instead with:

    scp -r -i /Applications/XAMPP/htdocs/keypairfile.pem uploads/* ec2-user@publicdns:/var/www/html/uploads
    
    0 讨论(0)
  • 2021-01-30 11:00

    Even if above solutions don't work, check permissions to destination file of aws ec2 instance. May be you can try with- sudo chmod 777 -R destinationFolder/*

    0 讨论(0)
提交回复
热议问题