识别无法访问的文件ssh

时间:2019-03-10 14:21:46

标签: bash ssh scp

我的操作系统是virtualbox中的Ubuntu16。 我正在尝试编写脚本以使用scp传输多个文件(文件名:t01,t02,t03)。 这是我的代码:

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

当我在终端上输入

./scriptname

我明白了

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

我不明白的一件事是,我实际上在脚本中写了“ /home/ian/.ssh/id_rsa”。但是错误消息显示为“ /home/ian/home/ian/.ssh/id_rsa”。我试图以不同的方式键入ssh_key目录,例如“ /.ssh/id_rsa”,但仍然无法正常工作。 我做错了什么? 谢谢!

1 个答案:

答案 0 :(得分:0)

1.0 告诉您它无法访问文件

因为您运行bash脚本的字典与文件所在的位置不同。

如果要将文件放在不同的词典中,则必须提供所有文件的完整路径。