在远程计算机上以交互方式创建新用户

问题描述 投票:-1回答:1

我有这样的功能:

function accountSetup() {
ssh -tt $HOST << EOF
    adduser billy
    [second command]
    [third command]
EOF
}

哪个终端挂了。我之前使用-tt标志成功地用EOF以交互方式执行了一些命令,但我似乎无法使用上述脚本在我的远程服务器上以交互方式创建新帐户。

这很好用,允许我设置密码,名称等:

function accountSetup() {
    ssh -tt $HOST adduser billy
}

但是,当我介绍我的其他必要的命令时,它开始变得愚蠢..我确信有一种更好的方法来执行它们而不必像这样重复登录:

function accountSetup() {
    ssh -tt $HOST adduser billy
    ssh -tt $HOST [third command]
    ssh -tt $HOST [second command]
}

问题:什么导致我的终端挂在我的第一个功能?如何以交互方式创建帐户并继续执行命令?

谢谢 :)

linux ssh terminal account
1个回答
0
投票

如果你告诉ssh从heredoc获取输入,它不能同时通过tty接收你的输入。

您可以将命令重写为:

function accountSetup() {
    ssh -t $HOST '
        adduser billy
        [second command]
        [third command]
    '
}
© www.soinside.com 2019 - 2024. All rights reserved.