Authentication Methods
The React Native SSH SFTP library supports two authentication methods: password-based and key-based authentication. Both methods establish a secure SSH connection to your remote server.Password Authentication
Password authentication is the simplest method. UseSSHClient.connectWithPassword() to connect with username and password credentials.
Method Signature
Key-Based Authentication
Key-based authentication provides stronger security by using SSH key pairs. UseSSHClient.connectWithKey() to connect with a private key.
Method Signature
KeyPair Interface
TheKeyPair interface represents an SSH key pair used for authentication. It contains the private key and optionally the public key and passphrase.
KeyPair Properties
string
required
The private key in PEM format (e.g.,
-----BEGIN RSA PRIVATE KEY-----)string
The public key in OpenSSH format (e.g.,
ssh-rsa AAAAB3NzaC1yc2EA...)string
The passphrase used to encrypt/decrypt the private key
Generating Key Pairs
You can generate SSH key pairs programmatically using thegenerateKeyPair() static method.
Method Signature
Return Type
Getting Key Details
UsegetKeyDetails() to retrieve information about an SSH private key, including its type and size.
Method Signature
Return Type
Security Best Practices
Recommendations
- Use Key-Based Authentication: Prefer key-based authentication over passwords for better security
- Protect Private Keys: Store private keys in secure storage (e.g., iOS Keychain, Android Keystore)
- Use Passphrases: Always encrypt private keys with strong passphrases
- Rotate Keys Regularly: Implement a key rotation policy for long-lived applications
- Validate Connections: Always handle connection errors and validate the server’s identity when possible
Secure Storage Example
The example above uses
expo-secure-store, but you should use the appropriate secure storage solution for your platform and framework.