Linux 通过 SSH 服务器获取 SCP 权限被拒绝到本地
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19777357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting permission denied for SCP over SSH server to local
提问by
I'm trying to scp
some files from a server to my local machine but I either get a permission denied, or the server is copying the files to the server
我正在尝试将scp
一些文件从服务器传输到我的本地计算机,但我的权限被拒绝,或者服务器正在将文件复制到服务器
ex:
前任:
scp username@host:/files/to/copy/from/\* /path/of/local/destination/
--> permission denied
scp username@host:/files/to/copy/from/\* /path/of/local/destination/
--> 权限被拒绝
scp username@host:/files/to/copy/from/\* ~
-->server copies to home directory on the server
scp username@host:/files/to/copy/from/\* ~
-->服务器复制到服务器上的主目录
scp username@host:/files/to/copy/from/\* ~/Desktop
-->server creates a file called Desktop on server
scp username@host:/files/to/copy/from/\* ~/Desktop
-->server 在服务器上创建一个名为 Desktop 的文件
I'm not sure what to do, this is on a Mac btw
我不知道该怎么做,这是在 Mac 上顺便说一句
采纳答案by Chris Hinshaw
You need to use the -r for recursive copy and make sure you have write permissions to the destination. Try doing a touch /path/to/local/destination/file
and see if you get permission denied. If so then use sudo scp to copy the files.
您需要使用 -r 进行递归复制,并确保您对目标具有写入权限。尝试做一个touch /path/to/local/destination/file
,看看你是否得到许可被拒绝。如果是这样,则使用 sudo scp 复制文件。
回答by PhucLy
I got the same issue. I use the username and password to scp files from windows to the username's account on ubuntu and get permision denied error. The reason is because one of the directory is owned by root. For example if the account is in /home/username then most likely /home is owned by root. If you change owner of /home then it may work. Try: sudo chown root: /folder
我遇到了同样的问题。我使用用户名和密码将 Windows 中的 scp 文件发送到 ubuntu 上的用户名帐户,并收到权限被拒绝的错误。原因是因为其中一个目录由 root 拥有。例如,如果帐户在 /home/username 中,那么 /home 很可能由 root 拥有。如果您更改 /home 的所有者,则它可能会起作用。尝试:sudo chown root: /folder
回答by mrwagaba
This can happen even if ssh works fine! The problem is File/Directory Permissions, for the most part! Using chmod 777 /path/dir/* gives write access to all the immediate children of /dir - including root files and directories. However, secondary files/directories are not affected by these permissions. Example: say i have this website: /var/www: index.php, css[mobile.css, global.css], js[init.js, fun.js], include[head.php, footer.php, body.php, fun.php]
即使 ssh 工作正常,这也可能发生!大多数情况下,问题在于文件/目录权限!使用 chmod 777 /path/dir/* 可以对 /dir 的所有直接子级(包括根文件和目录)进行写访问。但是,辅助文件/目录不受这些权限的影响。示例:假设我有这个网站:/var/www: index.php, css[mobile.css, global.css], js[init.js, fun.js], include[head.php, footer.php, body .php, fun.php]
To be able to overwrite fun.js: chmod 777 /var/www/js/*
为了能够覆盖 fun.js: chmod 777 /var/www/js/*
回答by user5748909
I had the same problem.
我有同样的问题。
Tried everything couldn't fix it, until I checked my ISP Gateway.
尝试了一切都无法修复它,直到我检查了我的 ISP 网关。
I work with a Zyxel gateway from my ISP and because that is far away from where I have another terminal I shoved a old Linksys DD-WRT flashed Router/Repeater in between. My host terminal that was connected to that Linksys was first connected to the Gateway with a DHCP table lock (I ordered the gateway to give the MAC from that terminal the same IP via DHCP). I did this because I first had a NAS server on that mac. Now I moved the terminal to another location and totally forgot the mac ip assignment.
我使用来自我的 ISP 的 Zyxel 网关,因为它离我有另一个终端的地方很远,所以我在中间推了一个旧的 Linksys DD-WRT 闪存路由器/中继器。我连接到 Linksys 的主机终端首先通过 DHCP 表锁连接到网关(我命令网关通过 DHCP 为来自该终端的 MAC 提供相同的 IP)。我这样做是因为我首先在那个 Mac 上有一个 NAS 服务器。现在我将终端移动到另一个位置,完全忘记了 mac ip 分配。
So now i had a WIFI repeater connected to the Gateway, and the computer with the mac assigned was connected to that.
所以现在我有一个 WIFI 中继器连接到网关,并且分配了 mac 的计算机连接到该网关。
The problem now was that my Gateway thought it was the old NAS whilst it was the other terminal, and assigned the IP to the WIFI repeater, and this was an IP conflict so scp
couldn't find the right location. Which on it's turn resulted in a access denied on scp
. Weird was that everything did work out fine, i could get on the internet, surf, mail, but with scp
it gave an conflict.
现在的问题是我的网关认为它是旧的NAS而它是另一个终端,并将IP分配给WIFI中继器,这是IP冲突所以scp
找不到正确的位置。反过来又导致访问被拒绝scp
。奇怪的是,一切都进行得很好,我可以上网、上网、收发邮件,但随之scp
而来的是冲突。
Changed it in the Gateway (removed the DHCP table), and assigned another ip to the terminal...
在网关里改了(去掉了DHCP表),给终端分配了另一个ip...
Now scp
command worked as before!
现在scp
命令像以前一样工作!
It took me 8 hours to figure it out so I thought to share this little hickup that can really frustrate you freaking butt off...
我花了 8 个小时才弄明白,所以我想分享这个小问题,它真的会让你感到沮丧……
Greets Pi @ir
问候 Pi @ir
回答by Jepsenwan
If there is a file with the same name as your source file in the destination directory, you need to remove it first. I encountered the issue like this.
如果目标目录中存在与源文件同名的文件,则需要先将其删除。我遇到了这样的问题。