mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: generate key pair using ssh2 for right public key format
This commit is contained in:
1 parent
03b2993b56
commit
261c6fc029
6 files changed
+20
-15
No files matched your search
@@ -1,3 +1,5 @@
|
||||
config
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ ENV USERNAME=commander
|
||||
|
||||
RUN adduser --disabled-password --gecos '' --shell /bin/zsh ${USERNAME}
|
||||
COPY ./quests/sshd_config /etc/ssh/sshd_config
|
||||
COPY ./ssh_pubkey /home/${USERNAME}/.ssh/authorized_keys
|
||||
COPY ./config/ssh_key.pub /home/${USERNAME}/.ssh/authorized_keys
|
||||
RUN chmod 600 /home/${USERNAME}/.ssh/authorized_keys \
|
||||
&& chmod 700 /home/${USERNAME}/.ssh \
|
||||
&& chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
"@types/passport-local": "^1.0.38",
|
||||
"@types/passport-oauth2": "^1.4.15",
|
||||
"@types/source-map-support": "^0",
|
||||
"@types/ssh2": "^1.15.1",
|
||||
"@types/swagger-ui-express": "^4.1.6",
|
||||
"@types/validator": "^13.11.9",
|
||||
"concurrently": "^8.2.2",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from 'fs'
|
||||
import { Duplex } from 'stream'
|
||||
import { Client } from 'ssh2'
|
||||
import Docker from 'dockerode'
|
||||
@@ -67,6 +66,7 @@ export async function attachContainer(
|
||||
config.docker.network
|
||||
].IPAddress
|
||||
const conn = new Client()
|
||||
console.log(config.docker.keypair.privateKey)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
conn
|
||||
@@ -100,7 +100,7 @@ export async function attachContainer(
|
||||
host: containerIp,
|
||||
port: 22,
|
||||
username: 'commander',
|
||||
privateKey: fs.readFileSync('/home/wancat/.ssh/id_ed25519'),
|
||||
privateKey: config.docker.keypair.privateKey,
|
||||
debug: console.log,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import fs from 'fs'
|
||||
import { generateKeyPairSync } from 'crypto'
|
||||
import ssh2 from 'ssh2'
|
||||
|
||||
const {
|
||||
utils: { generateKeyPairSync },
|
||||
} = ssh2
|
||||
|
||||
type KeyPair = {
|
||||
privateKey: string
|
||||
@@ -24,16 +28,7 @@ export function loadOrCreateKeyPair(privateKeyPath: string): KeyPair {
|
||||
}
|
||||
|
||||
export function generateKeyPair(): KeyPair {
|
||||
const { privateKey, publicKey } = generateKeyPairSync('rsa', {
|
||||
modulusLength: 2048,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem',
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem',
|
||||
},
|
||||
})
|
||||
const { private: privateKey, public: publicKey } =
|
||||
generateKeyPairSync('ed25519')
|
||||
return { privateKey, publicKey }
|
||||
}
|
||||
@@ -2067,6 +2067,13 @@
|
||||
dependencies:
|
||||
"@types/node" "^18.11.18"
|
||||
|
||||
"@types/ssh2@^1.15.1":
|
||||
version "1.15.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/ssh2/-/ssh2-1.15.1.tgz#4db4b6864abca09eb299fe5354fa591add412223"
|
||||
integrity sha512-ZIbEqKAsi5gj35y4P4vkJYly642wIbY6PqoN0xiyQGshKUGXR9WQjF/iF9mXBQ8uBKy3ezfsCkcoHKhd0BzuDA==
|
||||
dependencies:
|
||||
"@types/node" "^18.11.18"
|
||||
|
||||
"@types/stack-utils@^2.0.0":
|
||||
version "2.0.3"
|
||||
resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz"
|
||||
|
||||
Reference in new issue
Block a user