本地文件到终端 MacOSX 中的远程

我试图通过 VPN 使用 SSH 将本地文件‘ magent.tar.gz’从本地计算机复制到远程服务器。这是连接到虚拟机的内部 IP,我在这里使用它作为 xx.x.x.xx。

我在 SSH 帐户上有完全的“ sudo”访问权限,所以复制过来应该不会有任何问题。我试过以下方法:

我尝试了以下操作(magento.tar.gz 文件已经在本地根目录中)

sudo scp magento.tar.gz user@xx.x.x.xx/var/www/

这会要求我输入本地密码,然后返回 cp: user@xx.x.x.xx/var/www: Not a directory

sudo scp /Users/myname/magento.tar.gz user@xx.x.x.xx/var/www/

返回相同的。

我需要在任何地方包含 SSH 吗?

我需要先通过 SSH 连接到站点吗?

附注: 我已经设法通过 SSH 连接到服务器,浏览到目录,使一个文件夹和删除它使用 sudo mkdir等等,所以我肯定有权限。

279245 次浏览

At first, you need to add : after the IP address to indicate the path is following:

scp magento.tar.gz user@xx.x.x.xx:/var/www

I don't think you need to sudo the scp. In this case it doesn't affect the remote machine, only the local command.

Then if your user@xx.x.x.xx doesn't have write access to /var/www then you need to do it in 2 times:

Copy to remote server in your home folder (: represents your remote home folder, use :subfolder/ if needed, or :/home/user/ for full path):

scp magento.tar.gz user@xx.x.x.xx:

Then SSH and move the file:

ssh user@xx.x.x.xx
sudo mv magento.tar.gz /var/www

Just to clarify the answer given by JScoobyCed, the scp command cannot copy files to directories that require administrative permission. However, you can use the scp command to copy to directories that belong to the remote user.

So, to copy to a directory that requires root privileges, you must first copy that file to a directory belonging to the remote user using the scp command. Next, you must login to the remote account using ssh. Once logged in, you can then move the file to the directory of your choosing by using the sudo mv command. In short, the commands to use are as follows:

Using scp, copy file to a directory in the remote user's account, for example the Documents directory:

scp /path/to/your/local/file remoteUser@some_address:/home/remoteUser/Documents

Next, login to the remote user's account using ssh and then move the file to a restricted directory using sudo:

ssh remoteUser@some_address
sudo mv /home/remoteUser/Documents/file /var/www

Watch that your file name doesn't have : in them either. I found that I had to mv blah-07-08-17-02:69.txt no_colons.txt and then scp no-colons.txt server: then don't forget to mv back on the server. Just in case this was an issue.