大网数据广告活动
服务器运维问答

scp to copy file to remote server fails because of permissions

· 52CE 我爱测

I think my fundamental problem is that I don't fully understand how ssh / scp works. But I don't what to google to try to read up on my question. Problem Description I have created a bash script on serverA. It tries to scp a file…

问题原文

原帖链接 · Happydevdays · CC BY-SA 3.0

I think my fundamental problem is that I don't fully understand how ssh / scp works. But I don't what to google to try to read up on my question.

Problem Description

I have created a bash script on serverA. It tries to scp a file from serverA to serverB. This script will be scheduled as a cron job.

To test whether this script will work, I just tried to manually scp the file from serverA to serverB. But I'm getting a "Permission denied" error message on serverA.

I logged into serverA in the first place like this:

mycomputer#> ssh [email omitted]

Questions:

Is the manual scp test even a good idea? Because I'm logging in using my key into serverA but ultimately, it's the cron job that's going to trigger to scp command.

How do I know under what user ID / keys the cron job will attempt the copy?

What should I google to better understand how this all works?

Thanks.

已采纳解答

原帖链接 · Kevin K · CC BY-SA 3.0

If you want to automate something like this you will need to setup public / private keys on either side and then configure ssh for authorized keys in the direction you want to copy. Assuming you are using OpenSSh do the following on both systems:
ssh-keygen -t dsa
cd ~/.ssh
cp id_dsa identity
cp id_dsa.pub authorized_keys
cp id_dsa.pub systemname_id_dsa.pub

Now you will need to copy the last file from the source system to the target system's ~/.ssh directory and then run the following command:
cat systemname_id_dsa.pub >> authorized_keys

You should now be able to ssh / scp from source to target without a password for this user. I would suggest not doing this as root, but as another user as it opens up possible security issues when done as root.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。