Configuring SSH and SFTP Public Key Authentication NI Linux Real-Time Target

Updated Jan 9, 2024

Environment

Operating System

  • LabVIEW Real-Time (NI Linux Real-Time)

Other

  • PuTTY or other SSH client
  • A working SFTP Server

This article will go through the steps to connect to an SFTP server from NI Linux Real-Time target using public key authentication and LabVIEW.

Hardware Requirements:

  • NI Linux Real-Time targets

Software Requirements:

  • LabVIEW 2021 and later
  • LabVIEW Real-Time Module

Note: LabVIEW native OpenSSH and SFTP functionality is added on LabVIEW 2021.

Generate the private and public key pairs

  1. Open an SSH session to access the NI Linux Real-Time target shell using PuTTY .
  2. If you login as admin, change to lvuser account by executing su lvuser in the command line.
  3. As lvuser, execute ssh-keygen -t rsa to generate key pairs with RSA encryption.
  4. You can set a passphrase for the generated keys if desired. In this example, no passphrase was set.
  5. With default configuration, the identification (private key) is generated and saved at /home/lvuser/.ssh/id_rsa and public key is saved at /home/lvuser/.ssh/id_rsa.pub. Refer to the following figure.
Generate Key SS.png
 

Copy the public key to the remote SFTP server

If you can access to the server using password authentication, copy and paste the public key to the server using the scp command (refer to the following figure). If you dont have the password to the SFTP server, follow the below steps to transfer the public key manually.
 
copy key.png
  1. View the id_rsa.pub by executing the following command cat /home/lvuser/.ssh/id_rsa.pub
  2. Copy the contents and paste it in on the SFTP server .ssh/authorized_keys located in the server home directory. Note that the authorized_keys directory may change depending on how the SFTP server is configured. The authorized_keys file in the server will keep the client's public key information as below figure.
authorized keys.png
 

Accessing the remote SFTP server using LabVIEW in NI Linux Real-Time target.

  1. Open LabVIEW's SFTP List Directory.vi shipping example and create a copy.
  2. Create an empty project and add NI Linux Real-time target (eg. Compact RIO).
  3. Place the copy of SFTP List Directory.vi under the real-time target in the LabVIEW project.
  4. Open the SFTP List Directory.vi block diagram and add OpenSSH client object and the Additional Options property node.
  5. Wire string array constant to the input of Additional Options property node specifying the path of the private keys after -i arguments. Refer to the below figure.
BD.png

If you setup the public key authentication properly, you can access the remote SFTP server and list the directories using the modified SFTP List Directory.vi shipping example as shown below.
 
FP.png