I have created a simple VM in azure in which I will have to host a very simple server written in C.
To send the folder hosted on my computer containing the server to the virtual machine, I use the command from powershell:
scp -r <path_to_key.pem> <path_to_folder_on_my_pc> <azureuser#ip:/home/azureuser/>
The result of this command is
azureuser#ip: Permission denied (publickey).
lost connection
Would anyone who has had this problem have a solution ?
You need to copy your private key to the ~/.ssh/ directory on the host from which you want to transfer the file. Once you have done that, you can use the following command:
scp -i ~/.ssh/<name of your key>.pem <path of file to transfer> user#azureip:<target directory>
So for example you want to transfer file.txt to your Azure VM (IP of 10.10.10.10) with the private key named key.pem
scp -i ~/.ssh/key.pem file.txt user#10.10.10.10:/home/user/
To pull a file from your Azure VM to your local host, you reverse the order of the file to get and user#azureip.
scp -i ~/.ssh/key.pem user#10.10.10.10:/home/user/file.txt /home/user/
This problem may cause in your public key. please Ensure that the public key is also present in your home directory when you create the Azure Virtual machine with a public key. Meaning The public key was kept on your both local computer and virtual machine Then, with the permission accept from your local workstation, you can use ssh into your Azure Virtual Machine using the public key.
Reference: linux - Can't scp to Azure's VM - by ale93p
Suppose if you want to use the private key in the SCP then you will have to use the below command to copy files from the local system to the Azure VM
sudo scp -i ~/.ssh/id_rsa /path/cert.pem azureuser#ip.xxx.xxx.xxx:/home/file/user/local
Make sure that the Azure VM's incoming NSG rule has port 22 opened and by default VM'S page is reachable through port 80/443 over public IP address.
For more information in detail, please refer this link:
Use SSH keys to connect to Linux VMs - Azure Virtual Machines | Microsoft Docs
Use SCP to move files to and from a VM - Azure Virtual Machines | Microsoft Docs
Related
so i'm trying to copy a file for my directory to Azure ubuntu VM , SSH works just fine ,but scp command takes a lot of time and then i had this message
connect to host 10.x.x.x port 22: Connection timed out lost connection
this is the command i used :
scp -vvv -i .ssh/id_rsa BaltimoreCyberTrustRoot.crt.pem azureuser#10.x.x.x:/var/www/html
• AFAIK, the SCP command that you are using to try to connect to your Ubuntu Azure VM might not be correct as the correct command to connect to your Ubuntu Linux VM from your local machine to copy files between them is as follows: -
scp -r ./tmp/ azureuser#10.xxx.xxx.xxx:/home/file/user/local
In the above command, the SCP connection gets established successfully after entering the private key further which files in the local system in ‘/tmp’ directory is recursively getting copied in the Azure ubuntu VM specified in ‘/home/file/user/local’ directory. Thus, the whole directory tree as specified is copied from the local system to the Azure ubuntu VM.
• Also, if you want to use the private key in the ‘SCP’ command through SSH, then you will have to use the below command to copy files from the local system to the Azure ubuntu VM: -
sudo scp -i ~/.ssh/id_rsa /path/cert.pem azureuser#10.xxx.xxx.xxx:/home/file/user/local
Using ‘sudo’ to access a ‘root’ file, while ‘SCP’ is going to look for the identity file ‘id_rsa’ in ‘/root/.ssh/’ instead of in ‘/home/user/.ssh/’. That's why you will have to specify the identity file (private key) in the SCP command to connect to the Azure ubuntu VM and transfer files from local system to the VM.
Other than this, kindly ensure that port 22 is opened in the inbound NSG rule on the Azure ubuntu VM and the VM's default page is accessible on port 80/443 over public IP address and the Azure FQDN assigned.
For more information, kindly refer to the links below: -
Can't scp to Azure's VM
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/copy-files-to-linux-vm-using-scp#scp-a-directory-from-a-linux-vm
SO i am new to tech, and as previous posts suggests i am working with OCI. Currently i run a linux 8 VM on OCI. My goal is to run terraform scrips on the vm, and have the resources created in OCI.
Current problem:
The tf files i will be writing will be done so on my local windows 10 machine. The files will be saved in a local directory. I need a way of transferring these local files to a directory in my linux machine, in order to execute them!
Is anybody good with OCI is there capability for a sftp transfer using winscp?? I'm just not sure where to start. Anybody with good advice please aid me!
It depends of your OCI network configuration.
If your OCI compute VM is in a public subnet and you have an internet gateway, then you can use ssh to connect to it (using putty for instance). That means you can also use scp which lets move copy files over ssh. As you mentioned, WinSCP let's you connect to your OCI compute VM by using ssh and scp or sFTP. After installing it you can create a new connection using the public ip of your OCI compute VM and the private key.
My personal preference is to use MobaXterm to connect to ssh to
my OCI compute VMs. Once connected to a remote host using ssh, the
left pane directly displays a file browser for the remote host.
Drag-and-dropping a file there would initiate an sFTP transfer
automatically.
Please also note that scp is obsolete since 2019. SFTP or rsync could be used instead. Using MobaXterm, it can be done by opening a new terminal tab (which is local to your Windows machine) and type the rsync command you wish for instance rsync -v -P -e 'ssh -i "D:/my_folder/oci_api_key.pem"' /cygdrive/d/my_folder/*.tf opc#<oci_vm_ip>:/home/opc/my_folder
-v is increasing verbosity, to display more information. -P displays partial progress for each file transferred. -e lets you specify which command to use to run rsync. in this case I use ssh and pass the private key. More option are available and you can check them by typing man rsync.
If your OCI compute VM is in a private subnet, you would need to set up a bastion VM in a public subnet to first access the bastion and then the VM. Here is a blog post about how to achieve that using putty and WinSCP : https://www.ateam-oracle.com/ssh-tunnel-to-a-private-vm-using-a-bastion-host-in-oci
I'm currently using a sandbox environment to help gain an understanding of Linux and Ansible.
I have a rhel 7.6 VM where Ansible is installed/ran from that i connect to via moba. I then have 2 test VMs that i'd like to run Ansible against.
I cannot SSH from the Ansible VM to either of the test VM's (Permission denied public key) but i can connect directly to the test VM's.
How do i set up the keys/hosts? does the private key need to be uploaded to the Ansible VM?
Try to deploy ~/.ssh/id_rsa.pub key from Ansible control machine to one of your VM's in a file ~/.ssh/authorized_keys. Copy the contents of ~/.ssh/id_rsa.pub from the Ansible control machine in ~/.ssh/authorized_keys on the target host. You may use the ssh-copy-id command to perform this for you so long as you have access to the target host via some method.
another method different from best practice id_rsa.pub deployment is configuring inventory vars for your hosts/groups by setting ansible_user, ansible_ssh_pass (with vault usage), ansible_become_user, ansible_become_pass (with vault usage)
Requirement- Connecting SFTP server from local windows machines using WinSCP with keys
Technical- I have Azure VM(Windows 2012 server R2) in which Cygwin64 is installed for SFTP.
I want to connect SFTP server using RSA authentication i.e using keys.
I have edited the sshd_config file for RSA authentication. In cygwin64 folder I have also created .ssh folder and under that Authorized_keys file.
From local machine using putty I have generated Public and private keys and this public key I have entered in Authorized keys file but when I am trying to connect with that Private key it is saying "Server refused our key"
I have entered in Authorized keys file but when I am trying to connect
with that Private key it is saying "Server refused our key"
If you see this type of message, the first thing you should do is check your server configuration carefully. Common errors include having the wrong permissions or ownership set on the public key or the user’s home directory on the server.
Maybe you can follow those steps to setup CYGWIN authenticate with private key:
1.Install GYCWIN (OpenSSH and cygrunsrv)
2.configure sshd use this command ssh-host-config -y
3.Start SSHD service with this command cygrunsrv --start sshd
4.Add your public key to authorized_keys(we can copy public Key to this file):
jason#jasonvm ~/.ssh
$ ls -a
. .. authorized_keys id_rsa id_rsa.pub id_rsa1 known_hosts
$ cat authorized_keys
ssh-rsa AAAAB3Nxxx.......xxxxzaAVbeVFw==
jason#jasonvm ~/.ssh
$ pwd
/home/jason/.ssh
By the way, if you can't find this directory, you can use ssh-keygen.exe command to create this directory /home/user/.ssh, if you can't find this file authorized_keys, we should create it, and run this command chmod 600 authorized_keys
Afther that, we can use other Linux VM to SSH or SFTP this VM(we should open port 22 on Azure NSG inbound rules).
If you want to use winscp to login this VM, we should convert private key to .ppk. In this way, we can use this key to login this SFTP.
Note:
we can use winscp to convert .key to .ppk.
For test, you may try to use Putty to login azure vm with your private key, to make sure you are using the right private key and public key.
Update:
We can add open ssh and sftp like this:
I used to connect to Amazon web services using ssh command and application.pem key. Now when I try to connect to other platforms such as Github my ssh client looks for same application.pem key and tries to connect to AWS. How do I connect to Github or change the default host and key configuration.I am using a Ubuntu 13.10 system and following is my ssh output.
pranav#pranav-SVF15318SNW:~/.ssh$ ssh
Warning: Identity file application.pem not accessible: No such file or directory.
You need the identity file to login to the box. Use the command:
ssh -i (identity_file) username#hostname"
This worked for me. Write just the filename (without any slashes), unlike Amazon EC2 tutorial which asks you to enter:
ssh -i /path/key_pair.pem ec2-user#public_dns_name
and also check the permission