SFTP from RStudio Connect

I am looking to SFTP a file to another server from an RMarkdown report in RStudio Connect. I am running into challenges with the ssh configuration. A test document reveals

##                               sysname                               release 
##                               "Linux"         "4.18.0-240.1.1.el8_3.x86_64" 
##                               version                              nodename 
## "#1 SMP Thu Nov 19 17:20:08 UTC 2020"                         "nlrstudio01" 
##                               machine                                 login 
##                              "x86_64"                             "unknown" 
##                                  user                        effective_user 
##                     "rstudio-connect"                     "rstudio-connect"


## HOME                    /opt/rstudio-connect/mnt/tmp

So I know the user is "rstudio-connect" but when I try to su to that user (in order to generate the ssh keys) I get an error:

[root@nlrstudio01 ~]# sudo su - rstudio-connect 
su: warning: cannot change directory to /home/rstudio-connect: No such file or directory
This account is currently not available.

Again, all I'm looking to do is SFTP from my RSC server to another (non RSC) server, and our networking team needs the ssh key(s) from me for the user.


You don't have to place the SSH key into the users HOME since ssh/scp/sftp know the -i option:

-i identity_file
Selects a file from which the identity (private key) for public key authentication is read. The default is ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519, ~/.ssh/id_ed25519_sk and ~/.ssh/id_rsa. Identity files may also be specified on a per-host basis in the configuration file. It is possible to have multiple -i options (and multiple identities specified in configuration files). If no certificates have been explicitly specified by the CertificateFile directive, ssh will also try to load certificate information from the filename obtained by appending -cert.pub to identity filenames.