Copying a text file from my Ubuntu Windows Sub System to a remote instance through SSH

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying a text file from my Ubuntu Windows Sub System to a remote instance through SSH
# 1  
Old 12-20-2018
Copying a text file from my Ubuntu Windows Sub System to a remote instance through SSH

*Following questions involves use of YAML, BASH, SSH and Software called Ansible*

I am trying to learn how to use a Linux environment (in my case a Ubuntu Windows Sub System) to copy a text file from my files to a remote instance (in this case Amazon Web Services) by connecting via SSH.

I have set up directories and files in Ubuntu like so:

hosts > my_hosts

(hosts, playbook.yml, roles are all directories in home; hope the way I have shown it makes it clear)

The test.txt file contains a simple statement saying "Hello, World"; and this is what I want to send of to my remote instance.

The contents of the YAML files are as follows:

main.yml :
- name: Copy a file to the remote host
src: test.txt
dest: /tmp/test.txt

playbook.yml :
- hosts: my_hosts
- my-role

I am able to connect to the Amazon Web Services Remote Instances using a command in the following format:

sudo ssh -i ansible_instance_d**_****.pem "ubuntu@ec2-**-***-**-***"
(ignore quotation marks)

I assume I now need to somehow add something in the text file my_hosts that will allow me to connect to the remote instance; and subsequently copy the text file.

In order to then run the process is use:

ansible-playbook -i hosts playbook.yml

But i don't know what to put in the my_hosts file or whether everything else i have done is correct.

I've tried my best to explain what I am trying to do, please ask any more questions to help clarify.

# 2  
Old 12-21-2018

I would think that the standard scp functionality would be what you need as in;

sudo scp -i ansible_instance_d**_****.pem "local_path_to_file" "ubuntu@ec2-**-***-**-***"

Minus all the quotes of course.


# 3  
Old 12-21-2018
And yes, if you have ssh access, you have scp access. It's the same protocol.
# 4  
Old 12-21-2018
You will put the hostname you wish to use run ansible against.
In your case the hostname of amazon host written in that file.

Check out the /etc/ansible/hosts, it has comments about usage.
This is the default file used if you issue playbook without the -i parameter.

This presumes you have generated a ssh key for user you are issuing commands with and exchanged it with your amazon host.
See ssh-keygen and, since you are on Linux, ssh-copy-id if you haven't.
There is no need to use root accounts for any of the operations, only editing of default configuration files, which you are not doing.

It is also good to mention, using ansible to copy a file to one host is an overhead, since you can use scp to achieve the same.
If you require to execute several actions, copy files, start service(s), install packages on large number of servers ansible utility has a use case.

Otherwise it's like you are using a pneumatic hammer to kill a fly.

# 5  
Old 12-21-2018
Thanks for your reply,

When running that command:
sudo scp -i ansible_instance_d**_****.pem "local_path_to_file" "ubuntu@ec2-**-***-**-***"

(obviously with all the right input)

i get
scp: /./test.txt: Permission denied

The access permission for the file is -rwxrwxrwx
# 6  
Old 12-21-2018
The 'permission denied' is probably on the remote system, not yours. You are attempting to write to the root folder, which isn't going to work. Be sure to tell scp exactly where you want the file to end up.

scp -i ansible_instance_d**_****.pem "local_path_to_file" "ubuntu@ec2-**-***-**-***"

In that light, the 'sudo' is probably superfluous. You don't seem to need special permissions on your local system, and don't get elevated permissions on the remote one anyway.

Also, chmod 777 is not the magic sledgehammer to fix all problems. Try chmod 660, unless you really want to keep a world-writable script executable hanging around.
# 7  
Old 12-21-2018
Do you need sudo at all for ssh / scp? There might be reasons against it, but isn't it usually installed open for every user?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Unable to SSH from Windows client to Ubuntu Server

I'm trying to setup a small home network environment as a pet project. These are physical machines nothing virtual. Any help or ideas is greatly appreciated. I can ping between both machines and I have Samba established and can read/write different shares. When I try to SSH from Windows 8.1... (10 Replies)
Discussion started by: lombardi4851
10 Replies

2. Red Hat

Disable copying secure key's to remote system

Hi, We all know as we can connect remote system through ssh without entering username and password by copy the public key to remote host using ssh-copy-id. But my query is to i want to restrict the user as do not implement this feature.Whenever he is trying to login, he has to enter his/her... (1 Reply)
Discussion started by: mastansaheb
1 Replies

3. UNIX for Dummies Questions & Answers

Copying from remote SunOS to local Windows 7 computer

Can someone please help me with copying from remote computer to local computer? I have Winscp installed but for some reason i can seem to get into the server using winscp. I am currently logged on to the server, so its not a case of remote host unavailable. I really am not sure if the syntax... (2 Replies)
Discussion started by: dollypee
2 Replies

4. UNIX for Dummies Questions & Answers

Copying text from Windows to AIX - missing text?

Hi All, I'm hoping this is an easy question, but I'm having a weird problem trying to simply copy and paste text from MS Windows (XP) Notepad and then pasting into vi or vim in AIX. When I type "oslevel" I get "". The problem is that once the text is pasted, there are sections of text... (2 Replies)
Discussion started by: PlainInverted
2 Replies

5. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by:
1 Replies

6. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. Shell Programming and Scripting

Append Text To Remote Servers File Via SSH

Gentleman & Ladies, Please make me feel like and novice and explain why this is not working? I am attempting to ssh to a remote server via ssh and keys. I want to inject a file on the remote server with text. I am not achieving this. I would like to echo/inject the text on the remote... (1 Reply)
Discussion started by: abacus
1 Replies

8. Shell Programming and Scripting

ssh text into file on remote server

Hello, I have about 90 servers that I need to update snmp configs. I am trying to write a script that will echo 4 new lines of text into the snmpd.conf file. I have tested it locally and it works when the server ssh into itself but when I try to run the script to ssh into a remote server it logs... (5 Replies)
Discussion started by: mr_dthomas
5 Replies

9. UNIX for Dummies Questions & Answers

Copying files from a remote server to local system with cygwin

Hi. I'm sorry if I get on people's nerves asking this, but I don't really understand how to do this and unfortunately don't have the time to work through it step by step in books, etc. At University, we have a unix server that hosts our files. we each have a login and password to access it. I... (3 Replies)
Discussion started by: patwa
3 Replies

10. UNIX for Dummies Questions & Answers

Copying files from laptop to remote server using SSH

Hello, I'm sorry if this sounds like a very simple question, but I'm having some difficulty with it being a complete newbie to UNIx. I use Windows, and always have, but need some UNIX access for work, picking up files from our group space, etc. Basically, I'm using Cygwin and can SSH into the... (3 Replies)
Discussion started by: patwa
3 Replies
Login or Register to Ask a Question

Featured Tech Videos