Search code examples
bashsshscp

identify file not accessible ssh


My OS is Ubuntu16 in virtualbox. I'm trying to write a script to transfer multiple files(filename:t01,t02,t03) with scp. This is my code:

vim scriptname

#!/bin/bash
for a in {01..03}
do scp -i ~/home/username/.ssh/id_rsa -r t$a 
username@xx.xx.xx.xxx:/home/username/Desktop
done

And when I typed this in the terminal

./scriptname

I got this

Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No 
such file or directory.
t01: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No 
such file or directory.
t02: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No 
such file or directory.
t03: No such file or directory

One thing I couldn't understand is that I actually wrote "/home/ian/.ssh/id_rsa" in the script. But the error message showed "/home/ian/home/ian/.ssh/id_rsa". I have tried to type my ssh_key directory in different ways, such as "/.ssh/id_rsa" but still couldn't work. What did I do wrong? Thank you!


Solution

  • t01: No such file or directory Told you that it cannot access the file

    Because the dictionary you run the bash script is not the same to where the files are.

    If you want to put files not in the same dictionary, you have to give the full path for all of them.