# Ansible: Need to understand how can we use scp and ssh command with shell or script.

**URL:** <https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240>\
**Category:** Ansible Project\
**Created:** [April 18, 2017, 4:25pm UTC](https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240 "2017-04-18T16:25:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishant\_bawane](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nishant\_bawane](https://forum.ansible.com/u/nishant_bawane)\
**Post date:** [April 18, 2017, 4:25pm UTC](https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240/1 "2017-04-18T16:25:26Z")

</div>

for i in `cat /tmp/list`  
do  
echo $i  
scp HLC\_auth $i:.ssh/authorized\_keys  
scp known\_hosts.LLC $i:.ssh/known\_hosts  
ssh $i “rm -rf .ssh/id\_dsa\*”  
ssh $i “ssh-keygen -d”  
done  
Above the the task i need to run through playbook, please suggest how the playbook should look alike.

below is the code which run succesfully when i exclude scp and ssh commands -

shell: for i in `cat /home/dp794d/temp/list`;  
do echo $i;  
done

Need to include the scp and ssh command also under the same shell… how to perform that task.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 18, 2017, 5:03pm UTC](https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240/2 "2017-04-18T17:03:57Z")

</div>

There is many ways to do this, but you should probably start with the script module until you get some experience with Ansible  
[https://docs.ansible.com/ansible/script\_module.html](https://docs.ansible.com/ansible/script_module.html)

---

<div class="post-metadata">

**Author:** ![nishant\_bawane](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nishant\_bawane](https://forum.ansible.com/u/nishant_bawane)\
**Post date:** [April 18, 2017, 5:39pm UTC](https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240/3 "2017-04-18T17:39:26Z")

</div>

> **(attachments)**
>
> ![Auto Generated Inline Image 1.png](https://us1.discourse-cdn.com/ansible/original/2X/4/43177df6ed0af6a4738deea59fda92088d3a655f.png)

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 19, 2017, 5:29pm UTC](https://forum.ansible.com/t/ansible-need-to-understand-how-can-we-use-scp-and-ssh-command-with-shell-or-script/24240/4 "2017-04-19T17:29:06Z")

</div>

This is not a Ansible problem, so you might have better luck in a more bash/shell/ssh related community.

The only hint I will give you is to make that work you would need passwordless ssh keys in place.
