如何在 WinSCP 中使用 sudo
sudo WinSCP

> 
> 用截图了解如何在 WinSCP 中使用 sudo。
> 
> 
> 


![](/data/attachment/album/201903/13/115351nqxhm7qzq9zjecbv.png)


首先你需要检查你尝试使用 WinSCP 连接的 sftp 服务器的二进制文件的位置。


你可以使用以下命令检查 SFTP 服务器二进制文件位置：



```
[root@kerneltalks ~]# cat /etc/ssh/sshd_config |grep -i sftp-server
Subsystem sftp  /usr/libexec/openssh/sftp-server
```

你可以看到 sftp 服务器的二进制文件位于 `/usr/libexec/openssh/sftp-server`。


打开 WinSCP 并单击“高级”按钮打开高级设置。


![winSCP advance settings](/data/attachment/album/201903/13/115407mke8dkgizngtrd6h.jpg)


*WinSCP 高级设置*


它将打开如下高级设置窗口。在左侧面板上选择“Environment”下的 “SFTP”。你会在右侧看到选项。


现在，使用命令 `sudo su -c` 在这里添加 SFTP 服务器值，如下截图所示：


![SFTP server setting in winSCP](/data/attachment/album/201903/13/115409bw7tzrsvjl9s0spz.jpg)


*WinSCP 中的 SFTP 服务器设置*


所以我们在设置中添加了 `sudo su -c /usr/libexec/openssh/sftp-server`。单击“Ok”并像平常一样连接到服务器。


连接之后，你将可以从你以前需要 sudo 权限的目录传输文件了。


完成了！你已经使用 WinSCP 使用 sudo 登录服务器了。




---


via: <https://kerneltalks.com/tools/how-to-use-sudo-access-in-winscp/>


作者：[kerneltalks](https://kerneltalks.com) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
*Learn how to use sudo access in winSCP with screenshots.*

![](https://z5.kerneltalks.com/wp-content/uploads/2020/06/How-to-use-sudo-access-in-winSCP.png)

Before you move into configurations, make sure that the user is having **NOPASSWD **access to sudo to target user or root account. This means `/etc/sudoers`

file must have entry something like below –

```
user1 ALL=(root) NOPASSWD: ALL
```

Once you have proper [sudo configuration](https://kerneltalks.com/config/guide-sudo-configuration-unix-linux/) you can go ahead with WinSCP config. This is to ensure that once shell tries sudo it should be non-interactive.

First of all, you need to check where is your SFTP server binary located on the server you are trying to connect with WinSCP.

You can check SFTP server binary location with below command –

```
[root@kerneltalks ~]# cat /etc/ssh/sshd_config |grep -i sftp-server
Subsystem sftp /usr/libexec/openssh/sftp-server
```

Here you can see sftp server binary is located at `/usr/libexec/openssh/sftp-server`


Now open winSCP and click `Advanced`

button to open up advanced settings.

![](https://z5.kerneltalks.com/wp-content/uploads/2020/06/winscp-advanced-settings.jpg)

It will open up an advanced setting window like one below. Here select `SFTP `

under `Environment`

on the left-hand side panel. You will be presented with an option on the right hand side.

Now, add SFTP server value here with the command `sudo su -c`

here as displayed in the screenshot below –

![](https://z5.kerneltalks.com/wp-content/uploads/2020/06/SFTP-server-setting-in-winSCP.jpg)

So we added `sudo su -c /usr/libexec/openssh/sftp-server`

in settings here. Now click Ok and connect to the server as you normally do.

After connection, you will be able to transfer files from the directory where you normally need sudo permission to access.

That’s it! You logged to server using WinSCP and sudo access.

Does the user profile retain NOPASSWD access to root from then on? If so, how would one protect against malicious executables?

NOPASSWD to target account or root account! If you are giving it to root account then you must be knowing user well and hence authorizing his sudo to root with NOPASSWD.

i am able to login but not able to copy file from local to server. It gives Network error: Software caused connection abort.

I get an error connecting. “Cannot initialize SFTP protocol. Is the host running an SFTP server?”