简体   繁体   English

如何通过 PuTTY 的 psftp.exe sudo su

[英]How to sudo su over PuTTY's psftp.exe

With (PuTTY) PSFTP.exe it is possible to open open a shell script to perform certain actions on Linux.使用 (PuTTY) PSFTP.exe可以打开 shell 脚本以在 Linux 上执行某些操作。

In this example I am using psftp.exe to open get30.txt file.在这个例子中,我使用psftp.exe打开get30.txt文件。

%%PROJECT/ROOT_DIRECTORY%%\PuTTY\psftp.exe user@domain.nl -pw password -b "%%PROJECT/ROOT_DIRECTORY%%\Scripts\%%ENVIRONMENT/NAME%%\get30.txt"

In the get30.txt I have the following actions:get30.txt我有以下操作:

sudo su -l4097gps
cd /appl/gps/RIT/IN/30/RAP-T1
chmod 777 GP*.*
get -r /appl/gps/RIT/IN/30/RAP-T1
rm /appl/gps/RIT/IN/30/RAP-T1/*
quit

Unfortunately psftp does not recognise sudo su .不幸的是psftp不能识别sudo su

How can I sudo to a different user after I have logged on with my own user?使用自己的用户登录后,如何对其他用户执行sudo

It's not possible.这是不可能的。 Those commands you're sending aren't arbitrary shell commands - they're SFTP commands.您发送的那些命令不是任意的 shell 命令——它们是 SFTP 命令。 They happen to look like shell commands (rm, cd, etc), but they're just mirroring the shell equivalents.它们碰巧看起来像 shell 命令(rm、cd 等),但它们只是镜像 shell 等效项。 There is no 'sudo' command in most SFTP implementations, thus, you can't do it.大多数 SFTP 实现中都没有“sudo”命令,因此您不能这样做。

The only case where I'm wrong is if you're using a custom SFTP server and client that supports 'su', such as the one offered by Van Dyke software.我唯一错误的情况是,如果您使用的是支持“su”的自定义 SFTP 服务器和客户端,例如 Van Dyke 软件提供的那个。 However, you'd be using 'su' there, and be required to authenticate, instead of using 'sudo'.但是,您将在那里使用“su”,并且需要进行身份验证,而不是使用“sudo”。

Additionally, see this post on the serverfault stackoverflow:此外,请参阅 serverfault stackoverflow 上的这篇文章:

How to change user for more rights on a sftp client 如何更改用户以获得 sftp 客户端的更多权限

The sudo is a shell command, not an SFTP command. sudo是一个 shell 命令,而不是一个 SFTP 命令。

There's no sudo or equivalent in the SFTP protocol in general nor in psftp commands. SFTP 协议和psftp命令中通常没有sudo或等效psftp

Though if you are connecting to an OpenSSH server, you can instruct it to run the SFTP subsystem/server with elevated privileges using a command like:但是,如果您要连接到 OpenSSH 服务器,则可以使用以下命令指示它以提升的权限运行 SFTP 子系统/服务器:

sudo /bin/sftp-server

Unfortunately the psftp does not allow you to change the command used to launch the SFTP server.不幸的是, psftp不允许您更改用于启动 SFTP 服务器的命令。

You can use WinSCP instead:您可以改用 WinSCP:

open sftp://user:password@domain.nl/ -rawsettings SftpServer="sudo /bin/sftp-server"

But there's lot of limitations to allow this working.但是有很多限制来允许这个工作。 Particularly the sudo may not require password.特别是sudo可能不需要密码。 For details, see WinSCP FAQ How do I change user after login (eg su root)?有关详细信息,请参阅 WinSCP FAQ如何在登录后更改用户(例如 su root)?

See also the guide to converting PuTTY PSFTP script to WinSCP script .另请参阅将 PuTTY PSFTP 脚本转换为 WinSCP 脚本的指南

(I'm the author of WinSCP) (我是 WinSCP 的作者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM