Connect to server.example using ~/.ssh/project_key.
The key has a non-default name, so specify it on the command line.
Which command is appropriate?
The OpenSSH client's -i option selects the private-key file. Protect that file on the client.
Detailed explanation
ssh -p ~/.ssh/project_key server.exampleIncorrect. -p selects a TCP port, not a key file.
Incorrect. -p selects a TCP port, not a key file.
ssh -k ~/.ssh/project_key server.exampleIncorrect. -k does not select the identity file in this command.
Incorrect. -k does not select the identity file in this command.
ssh -K ~/.ssh/project_key server.exampleIncorrect. -K is not the standard identity-file option.
Incorrect. -K is not the standard identity-file option.
ssh -i ~/.ssh/project_key server.exampleCorrect. ssh -i ~/.ssh/project_key server.example selects the specified key.
Correct. ssh -i ~/.ssh/project_key server.example selects the specified key.
Try it yourself
An example you can run in a temporary verification environment.
ssh -G -i ~/.ssh/project_key server.example | grep '^identityfile'Expected result
接続せず、指定identity fileを含む設定を表示するKey points
- -i
- Private key
- Client side
Notes
- Environment: OpenSSH 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.