How to copy files from one machine to another machine - shell

I want to copy /home/cmind012/m.sh from one system to another system (both system Linux) using shell script.
Command $
scp /home/cmind012/m.sh cmind013:/home/cmind013/tanu
getting message
ssh: cmind013: Name or service not known
lost connection

It seems that cmind013 is not being resolved, I would try using first
nslookup cming013
and see what why donesn't it resolve.

It seems that you are missing the IP Address/Domain of the remote host. The format should be user#host:[directory]
You could do the following:
scp -r [directory/files] [remote host]:[destination directory]
ex: scp -r /var/www/html/* root#192.168.1.0:/var/www/html/

Try the following command:
scp /home/cmind012/m.sh denil#172.22.192.105:/home/denil/

Related

Trying to copy files between two different servers

I am trying to copy one file from stage host to dev host by using following command in UNIX box. However I am getting an error "no such file or directory".
$ scp [-r] [[user#]xxx-stage.example.com:]/apps/usr/example/example.html [[user#]xxx-dev.example.com:]/apps/usr/example
[[user#]xxx-dev.example.com:]/apps/usr/example: No such file or directory
you can try this.
ssh -A -t user#remote1 scp /tmp/example.html user#remote2:/tmp/
you can try
scp -r ipaddress:file ipaddress2:desired location

Copy file from remote to local using ssh

I'm trying to copy a file from a Ubuntu server to my mac but I keep receiving a No such file or directory error.
After I ssh in I'm using:
scp -p 8888 me#xx1.xx1.xx1.xx1:/var/www/html/00000001.jpg /Users/myusername/Documents/
But receive the error:
/Users/myusername/Documents/: No such file or directory
Is this error telling me that there is no such file or directory on my local machine? Any advice as to how to fix would be greatly appreciated.
Don't ssh in to your server first. Just execute that scp command from your local machine.
EDIT:
Also, the -p should be capitalized (according to the manpage on my machine), so:
scp -P 8888 your_username#remotehost.edu:/var/www/html/00000001.jpg /Users/myusername/Documents/
Yes, it's talking about your local machine. I'm guessing that you might have just typed something wrong. Try doing it like this instead:
scp -P 8888 me#xx1.xx1.xx1.xx1:/var/www/html/00000001.jpg ~/Documents/
Make sure you're typing this command at your Mac OS X Terminal prompt, not on the actual remote server. xx1.xx1.xx1.xx1 should be the remote Ubuntu machine ("pull" the file down to your machine, don't try to "push" it).
Also, although it's ssh -p, it's scp -P. For scp, -p just preserves modification times, and -P is the port.
Maybe you have multiple ssh connections open.
Try close all other connections and restart the scp command.

Transferring a makefile using PUTTY scp

I've written a makefile and I am trying to send it to the folder containing the program I am trying to compile.
the command I am trying is:
scp username#host.com ~/destinationdirectory C\Users\Myname\Desktop\Makefile
the response I get is:
ssh: Could not resolve hostname C: Name or service not known
lost connection
any thoughts on how I can get this to work?
The command syntax is:
scp <source> user#host:destination
With that, you may try:
scp C\Users\Myname\Desktop\Makefile username#host.com:destinationdirectory/
I don't use windows, so this might not work for you, but try the following:
scp username#host.com:/home/username/destinationdirectory C\Users\Myname\Desktop\Makefile

Using scp to copy a file to Amazon EC2 instance?

I am trying to use my Mac Terminal to scp a file from Downloads (phpMyAdmin I downloaded online) to my Amazon EC2 instance.
The command I used was:
scp -i myAmazonKey.pem phpMyAdmin-3.4.5-all-languages.tar.gz hk22#mec2-50-17-16-67.compute-1.amazonaws.com:~/.
The error I got:
Warning: Identity file myAmazonKey.pem not accessible: No such file or directory.
Permission denied (publickey).
lost connection
Both my myAmazonkey.pem and phpMyAdmin-3.4.5-all-languages.tar.gz are in Downloads, so then I tried
scp -i /Users/Hello_Kitty22/Downloads/myAmazonKey.pem /Users/Hello_Kitty22/Downloads/phpMyAdmin-3.4.5-all-languages.tar.gz hk22#mec2-50-17-16-67.compute-1.amazonaws.com:~/.
and the error I got:
Warning: Identity file /User/Hello_Kitty22/Downloads/myAmazonkey.pem not accessible: No such file or directory.
Permission denied (publickey).
lost connection
Can anyone please tell me how to fix my problem?
p.s. there is a similar post: scp (secure copy) to ec2 instance without password
but it doesn't answer my question.
Try specifying the user to be ec2-user, e.g.
scp -i myAmazonKey.pem phpMyAdmin-3.4.5-all-languages.tar.gz ec2-user#mec2-50-17-16-67.compute-1.amazonaws.com:~/.
See Connecting to Linux/UNIX Instances Using SSH.
second directory is your target destination, don't use server name there. In other words, you don't need to mention machine name for the machine you're currently in.
scp -i /path/to/your/.pemkey -r /copy/from/path user#server:/copy/to/path
-r if it's a directory.
Your key must not be publicly viewable for SSH to work. Use this command if needed:
chmod 400 yourPublicKeyFile.pem
You should be on you local machine to try the above scp command.
On your local machine try:
scp -i ~/Downloads/myAmazonKey.pem ~/Downloads/phpMyAdmin-3.4.5-all-languages.tar.gz hk22#mec2-50-17-16-67.compute-1.amazonaws.com:~/.
Here are the details of what works for an EC2 instance:
scp -i /path/to/whatever.pem /users/me/path-to-file ec2-user#ec2-55-55-555-555.compute-1.amazonaws.com:~
Few notes for beginning:
Note the spaces between the three parameters given after the -i
scp stands for secure copy protocol. Knowing the words makes it easier to remember the command.
-i dictates that you need to give the .pem file as the next param. If there is no -i, than you do not need a .pem.
Note the :~ at the end of the destination for the EC2 instance.
I had exactly same problem, my solution was to
scp -i /path/pem -r /path/file/ ec2-user#public aws dns name: (leave it blank here)
once you done this part, get into ssh server and mv file to desired location
This just worked for me. I used a combination of two other answers to this question.
scp -i /Users/me/documents/myKP.pem -r /Users/me/desktop/testDir \
ec2-user#ec2-11-111-11-11.compute-1.amazonaws.com:/home/ec2-user/remoteDir
The "ec2-user#ec2-11-111-11-11.compute-1.amazonaws.com" is copy-and-pasted from your ec2 instance's public DNS.
Send file from Local to Server:
scp -i .ssh/awsinstance.pem my_local_file
ubuntu#XX.XXX.XXX.XXX:/home/ubuntu
Download file from Server to Local:
scp -i .ssh/awsinstance.pem
ubuntu#XX.XXX.XXX.XXX:/home/ubuntu/server_file .
scp -i ~/path to pem file/file.pem -r(for directory) /PATH OF LOCAL/localfile user#hostname:PATH OF SERVER/serverdirectory
Below SCP format works for me
scp -i /path/my-key-pair.pem ec2-user#ec2-198-51-100-1.compute-1.amazonaws.com:~/SampleFile.txt ~/SampleFile2.txt
SampleFile.txt: It will be the path from your root directory(In my case, /home/ubuntu). in my case the file which I wanted to download was at /var/www
SampleFile2.txt: It will be path of your machine's root path(In my case, /home/MyPCUserName)
So, I have to write below command
scp -i /path/my-key-pair.pem ec2-user#ec2-198-51-100-1.compute-1.amazonaws.com:~/../../var/www/Filename.zip ~/Downloads
Public DNS
scp -i /path/my-key-pair.pem /path/my-file.txt ec2-user#my-instance-public-dns-name:path/
(IPv6)
scp -i /path/my-key-pair.pem /path/my-file.txt ec2-user#\[my-instance-IPv6-address\]:path/
SCP Commend
Send File from Local To Remote Server
sudo scp -i ../Downloads/new_bb_key.pem ./dump.zip ubuntu#13.127.124.129:~/.
Send File from Remote Server To Local
sudo scp -i ~/Downloads/new_bb_key.pem ubuntu#13.127.124.129:/home/ubuntu/LatestDBdump.zip Downloads/
try to use this command
if your instance is using ubuntu
scp -i myAmazonKey.pem phpMyAdmin-3.4.5-all-languages.tar.gz ec2-user#mec2-50-17-16-67.compute-1.amazonaws.com:~/.
you can get more info about your instance from here
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html
The process of using SCP to copy files from a local machine to an AWS EC2 Linux instance is covered step-by-step (including the points mentioned below) in this video.
To correct this particular issue with using SCP:
You need to specify the correct Linux user. From Amazon:
For Amazon Linux, the user name is ec2-user.
For RHEL, the user name is ec2-user or root.
For Ubuntu, the user name is ubuntu or root.
For Centos, the user name is centos.
For Fedora, the user name is ec2-user.
For SUSE, the user name is ec2-user or root.
Otherwise, if ec2-user and root don't work, check with your AMI provider.
Your private key must not be publicly visible. Run the following command so that only the root user can read the file.
chmod 400 /path/to/yourKeyFile.pem
Check the permissions on the .pem file...openssh usually doesn't like world-readable private keys, and will fail (iir, scp doesn't do a great job of providing this feedback to the user).
Can you simply ssh with that key to your AWS host?
First you should change the mode of .pem file from read and write mode to read only mode. This can be done just by a single command in terminal sudo chmod 400 your_public_key.pem
I tried all the suggestions mentioned above and nothing worked. I terminated the current instance, launched another one and repeated the same exact process. This time no problems. Sometimes it might be the remote ami's fault.
I would use:
scp -i "path to .pem file" "file to be copeide from local machine" username#amazoninstance: 'destination folder to copy file on remote machine'

Moving a folder from Desktop to the server?

I have a folder in my Desktop. I want to copy it to my server in Terminal.
I tried this unsuccessfully
[~/bin]# cp -r /Users/Sam/Desktop/tig-0.14.1 ~/bin/
cp: cannot stat `/Users/Sam/Desktop/tig-0.14.1': No such file or directory
[edit]
I run the command in my server. The problem seems to be in the fact that "/Users/Sam/Desktop/tig-0.14.1" is a folder in my Mac, not in my server.
Perhaps, I cannot move the folder so simply to my server because my server do not know where my folder locates.
I have always moved the folder by GUI. Is the same possible also just in terminal?
From the server:
scp -r username#A.B.C.D:~/Desktop/tig-0.14.1/ ~/bin/
username is your shortname on your local mac.
A.B.C.D is the IP address of your local mac as seen by the server.
You will be prompted for your password.
Or if you wanted to push from your local client:
scp -r ~/Desktop/tig-0.14.1/ serveruser#W.X.Y.Z:~/bin/
serveruser is the user on the server whose ~/bin you want to copy into.
W.X.Y.Z is the IP address of the server as seen by your client.
You will be prompted to enter serveruser's password.
scp is part of ssh. See 'man scp' (from the terminal) for more info.
From your Mac (not the server):
# scp -r ~/Desktop/tig-0.14.1 myUsername#myServerName:~/bin
replace myUsername and myServerName appropriately.
cp is not the correct command. Try scp instead; it has similar use and you can use it like this: (see the manual for reference)
from linux client:
scp user1#host1://Users/Sam/Desktop/tig-0.14.1 ~/bin/
if you use a windows client you can use winscp to do this in "drag&drop" style
cp: cannot stat/Users/Sam/Desktop/tig-0.14.1': No such file or directory`
That's the problem, alright: the file you're trying to copy is not where you thought, or not named what you typed. As suggested in comments you can try using tab completion at the prompt to make sure you have everything correct:
# cp /Users/Sam/Desk<TAB>
# cp /Users/Sam/Desktop/tig<TAB>
# cp /Users/Sam/Desktop/tig-0.14.1.tar.gz
Note that tig-0.14.1.tar.gz is probably the actual file name, as found in the wild...

Resources