-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateSSHonWindows.ps1
44 lines (30 loc) · 1.32 KB
/
CreateSSHonWindows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Install the OpenSSHUtils module to the server. This will be valuable when deploying user keys.
Install-Module -Force OpenSSHUtils -Scope AllUsers
# Start the ssh-agent service to preserve the server keys
Start-Service ssh-agent
# Now start the sshd service
Start-Service sshd
cd ~\.ssh\
ssh-keygen
ssh-keygen -m PEM -t rsa -b 4096
#ssh-keygen detailed
https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/virtual-machines/linux/create-ssh-keys-detailed.md
ssh-keygen \
-m PEM \
-t rsa \
-b 4096 \
-C "azureuser@myserver" \
-f ~/.ssh/mykeys/myprivatekey \
-N mypassphrase
# Make sure you're running as an Administrator
Start-Service ssh-agent
# This should return a status of Running
Get-Service ssh-agent
# Now load your key files into ssh-agent
ssh-add ~\.ssh\id_ed25519
# Make sure that the .ssh directory exists in your server's home folder
ssh user1@[email protected] mkdir C:\users\user1\.ssh\
# Use scp to copy the public key file generated previously to authorized_keys on your server
scp C:\Users\user1\.ssh\id_ed25519.pub user1@[email protected]:C:\Users\user1\.ssh\authorized_keys
# Appropriately ACL the authorized_keys file on your server
ssh --% user1@[email protected] powershell -c $ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission C:\Users\user1\.ssh\authorized_keys