Skip to content

Commit 9e4ec35

Browse files
committed
Resolve #112.
1 parent 09351c8 commit 9e4ec35

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
159 KB
Loading

tutorials/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ vault_localdisk
1111
sftp_publickeyauth
1212
sftp_publickeyauth_1password
1313
sftp_publickeyauth_bitwarden
14+
sftp_publickeyauth_yubikey
1415
cli_github_action
1516
:::
1617

@@ -37,5 +38,8 @@ Authenticate with SSH private key saved in 1Password.
3738
### [Configure Bitwarden SSH Agent](sftp_publickeyauth_bitwarden.md)
3839
Authenticate with SSH private key saved in Bitwarden.
3940

41+
### [Use YubiKey](sftp_publickeyauth_yubikey.md)
42+
Authenticate with SSH private key saved on YubiKey.
43+
4044
## [Use Cyberduck CLI GitHub Action](cli_github_action.md)
4145
Use Cyberduck CLI Docker Container in GitHub Actions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Configure Public Key Authentication for SFTP using _yubikey-agent_
2+
====
3+
4+
> Public-key authentication using _[yubikey-agent](https://github.com/FiloSottile/yubikey-agent)_ SSH Agent allows you to connect to a remote server without a password. Instead of passwords, you use a pair of keys (private and public) for authentication. The private key is kept secret, while the public key is shared with the server.
5+
6+
Authenticate SSH connections with the SSH private key stored on a _YubiKey_. Setup _yubikey-agent_, a seamless ssh-agent for _YubiKey_.
7+
8+
:::::{tabs}
9+
::::{group-tab} macOS
10+
11+
1. Install `yubikey-agent` using [Homebrew](https://brew.sh) on macOS.
12+
```
13+
brew install yubikey-agent
14+
```
15+
16+
2. Launch _YubiKey_ Agent
17+
```
18+
brew services start yubikey-agent
19+
```
20+
3. Run setup to create a new SSH key on the _YubiKey_
21+
```
22+
🔐 The PIN is up to 8 numbers, letters, or symbols. Not just numbers!
23+
❌ The key will be lost if the PIN and PUK are locked after 3 incorrect tries.
24+
25+
Choose a new PIN/PUK:
26+
Repeat PIN/PUK:
27+
28+
🧪 Reticulating splines...
29+
30+
✅ Done! This YubiKey is secured and ready to go.
31+
🤏 When the YubiKey blinks, touch it to authorize the login.
32+
33+
🔑 Here's your new shiny SSH public key:
34+
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEX52rEAXMPs7m75uvckZwhV6k+pUFRADkSaGhhALt484hBAP8C1XOHISJzAF46oWgVopDXP/4BD58UwkeMDSJc=
35+
36+
Next steps: ensure yubikey-agent is running via launchd/systemd/...,
37+
set the SSH_AUTH_SOCK environment variable, and test with "ssh-add -L"
38+
39+
💭 Remember: everything breaks, have a backup plan for when this YubiKey does.
40+
```
41+
42+
4. Specify the socket the _YubiKey_ SSH Agent is listening in your OpenSSH configuration file `~/.ssh/config`.
43+
```
44+
Host *
45+
IdentitiesOnly yes
46+
IdentityAgent /opt/homebrew/var/run/yubikey-agent.sock
47+
```
48+
49+
5. Copy the SSH public from the output and save it to a file:
50+
```
51+
echo "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEX52rEAXMPs7m75uvckZwhV6k+pUFRADkSaGhhALt484hBAP8C1XOHISJzAF46oWgVopDXP/4BD58UwkeMDSJc=" > ~/.ssh/yubikey.pub
52+
```
53+
54+
6. Add a new [Bookmark](../cyberduck/bookmarks.md) in Cyberduck or Mountain Duck. Enter the alias from your OpenSSH configuration or the hostname in _Server_. You do **not** need to set a value for _Password_.
55+
56+
:::{image} _images/Bookmark_Panel.png
57+
:alt: Bookmark Panel
58+
:width: 600px
59+
:::
60+
61+
:::{tip}
62+
The public key selected allows to identify the corresponding private key retrieved from the SSH agent avoiding _Too many authentication failures_.
63+
:::
64+
65+
7. Add the public key to the `authorized_keys` in your `~/.ssh` directory on the server running OpenSSH.
66+
```
67+
ssh-copy-id -fi ~/.ssh/yubikey.pub user@remotehost
68+
```
69+
70+
8. Verify the agent is running and can access keys on your _YubiKey_
71+
```
72+
SSH_AUTH_SOCK="/opt/homebrew/var/run/yubikey-agent.sock" ssh-add -l
73+
256 SHA256:etGxFZK2D+AFJITkoaAm5BoxHqQlZfIWkhnSMMjGZ2I YubiKey #15203057 PIV Slot 9a (ECDSA)
74+
```
75+
76+
9. Connect to the server and enter the PIN for the _YubiKey_ to unlock the private key:
77+
78+
:::{image} _images/YubiKey_Agent_PIN_Prompt.png
79+
:alt: YubiKey Agent PIN Prompt
80+
:width: 600px
81+
:::
82+
83+
:::{important}
84+
Touch the _YubiKey_ when it blinks to verify human interaction and allow to proceed the connection.
85+
:::
86+
87+
:::{warning}
88+
If you receive a prompt to login using a password with the message _Unknown key format for file yubikey.pub. Please contact your web hosting service provider for assistance_, there was a failure accessing the private key. Ensure the SSH agent is running.
89+
:::
90+
91+
::::
92+
:::::
93+
94+
## References
95+
96+
- [Yubico](https://www.yubico.com/)
97+
- [Guide to using YubiKey for GnuPG and SSH](https://github.com/drduh/YubiKey-Guide)
98+
- [Seamless ssh-agent for YubiKey](https://github.com/FiloSottile/yubikey-agent)

0 commit comments

Comments
 (0)