Nxc / Use Private Key For Authentication
Use Private Key For Authentication
Authenticate to a remote host using SSH with a private key.
nxc ssh <192.186.178.2> -u <path/to/usernames.txt> -p <password> --key-file <path/to/id_rsa> nxc ssh <192.186.178.2> -u <path/to/usernames.txt> -p <password> --key-file <path/to/id_rsa> #!/bin/bash
# Use Private Key For Authentication
nxc ssh {{192.186.178.2}} {{[-u|--username]}} {{path/to/usernames.txt}} {{[-p|--password]}} {{password}} --key-file {{path/to/id_rsa}} import subprocess
# Use Private Key For Authentication
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"nxc",
"ssh",
"<192.186.178.2>",
"-u",
"<path/to/usernames.txt>",
"-p",
"<password>",
"--key-file",
"<path/to/id_rsa>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: nxc not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
During a security audit requiring SSH access to a known IP with a valid key.
Pro Tip
Check if `sshd` allows public key authentication; if not, login may fail even with a valid key.
Command Builder
Tune the command before you copy it
nxc ssh <192.186.178.2> -u <path/to/usernames.txt> -p <password> --key-file <path/to/id_rsa> Anatomy of Output
Understanding the result
Welcome to Ubuntu 20.04 LTS OS Version Indicates the version of the operating system.
Last login: Fri Oct 13 10:03:06 2023 from 192.186.178.1 Login Timestamp & IP The last successful login details.
# whoami Current User Command verifying the logged-in user (the effective user after authentication).
Troubleshooting
Common pitfalls
ssh: Could not resolve hostname 192.186.178.2: Name or service not known
Solution: Verify the IP address format.
Permission denied (publickey).
Solution: Ensure the correct private key is specified and has proper permissions.
ssh: connect to host 192.186.178.2 port 22: Connection timed out
Solution: Check the network connectivity and firewall settings on the target.
Command Breakdown
What each part is doing
-
nxc - Base Command
- The executable that performs this operation. Here it runs Nxc before the shell applies any redirect operators.
-
<192.186.178.2> - 192.186.178.2
- The value supplied for 192.186.178.2.
-
-u - u| username
- The user value supplied to this command.
-
<path/to/usernames.txt> - path to usernames.txt
- The user value supplied to this command.
-
-p - p| password
- The value supplied for p| password.
-
<password> - password
- The value supplied for password.
-
<path/to/id_rsa> - path to id rsa
- The value supplied for path to id rsa.
-
-u - Command Option
- Tool-specific option used by this command invocation.
-
-p - Command Option
- Tool-specific option used by this command invocation.
-
--key-file - Command Option
- Tool-specific option used by this command invocation.
Alternative Approaches
Comparable commands in other tools
Alternative security tools for the same job.
openssl dgst -sha256 -binary -out <output_file> <input_file> John / Crack Password Hashes Specific Hash Format john --format=<md5crypt> <path/to/hashes.txt> John / Crack Password Hashes Enable Word Mangling john --rules <path/to/hashes.txt> John / Restore Interrupted Cracking Session john --restore=<path/to/mycrack.rec> Safe / Generate Ssh Keypair And Store safe ssh <2048> <path/to/secret>