识别文件无法访问ssh

问题描述 投票:-1回答:1

我的操作系统是虚拟机中的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 
[email protected]:/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”,但仍无法正常工作。我做错了什么?谢谢!

bash ssh scp
1个回答
0
投票

t01: No such file or directory告诉你,它无法访问该文件

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

如果要将文件放在同一个字典中,则必须为所有文件提供完整路径。

© www.soinside.com 2019 - 2024. All rights reserved.