0

How can I execute a system command that normally requires user interaction? For example, I would like to run:

system("ssh-keygen") 

At the terminal prompt, it looks like this:

iMac-2:~ admin$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/admin/.ssh/id_rsa):

In RStudio, this command causes the application to hang.

I've tried the options wait=FALSE, AND invisible=FALSE, but they don't seem to help.

R: Using wait=FALSE in system() with multiline commands

`system()` interactive .exe/binary from R/Rgui

Community
  • 1
  • 1
Bobby
  • 1,585
  • 3
  • 19
  • 42
  • `system` function has an `input=` parameter. You could try to code user input into this parameter. – mt1022 Dec 21 '16 at 14:47

1 Answers1

2

Well.

There are some commands who let you to put the parameters in command line:

For example:

ssh-keygen

If you run: ssh-keygen --help you could find something like this:

ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]

It says you could specify the parameters in command line.

In my case I've tested with:

ssh-keygen -f /tmp/id_rsa -P ""

And I don't need to interact with the program.

Like another example like adduser command, you could try with:

echo PASSWORD | passwd USERNAME --stdin

Ivan Botero
  • 209
  • 5
  • 13
  • Thanks, that helps a lot. Do you know if there's a way to provide the password with `scp` and `ssh`? – Bobby Dec 21 '16 at 14:42
  • 1
    There is a command named 'sshpass' but....i dont think it could be a great way to use pass a password, because you could use it in a script and somebody could read the password. I think you could configure a 'Trust Relationship' between your hosts, it could help you too. – Ivan Botero Dec 21 '16 at 14:45