Answers:
用途ssh -t
:
男人SSH
-t Force pseudo-tty allocation. This can be used to execute arbitrary
screen-based programs on a remote machine, which can be very useful,
e.g. when implementing menu services. Multiple -t options force tty
allocation, even if ssh has no local tty.
所以你的命令将是
ssh remotemachine -t "sudo -u www mkdir -p /path/to/new/folder"
如果您不想输入密码,则可以(如果允许)sudoers
使用command 进行修改visudo
。
添加参数NOPASSWD:
,例如
username ALL=(ALL) NOPASSWD: /bin/mkdir
如果您无法编辑/ etc / sudoers,则可以使用sudo -S
:
须藤文
-S The -S (stdin) option causes sudo to read the password from
the standard input instead of the terminal device. The
password must be followed by a newline character.
这样,命令将是
echo "your_password" | ssh remotemachine -t \
"sudo -S -u www mkdir -p /path/to/new/folder"
请记住,这会将您的密码添加到Shell的命令历史记录中(使用bash,将是~/.bash_history
文件)。