如何使用存储在变量中的文件的内容,而不是使用bash中的内容创建文件

时间:2017-01-19 14:06:02

标签: bash

我正在尝试将OpenSSL私钥转换为OpenSSH公钥。 我使用以下命令执行此操作。 ssh-keygen -f -y

现在我想要使用包含“OpenSSL-Private-Key-File”内容的变量来完成,而不是使用“OpenSSL-Private-Key”本身。怎么能在bash中完成。我试图避免创建文件。请帮忙。

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

read -r -d '' VARIABLEKEY << EOM
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAwbTpqo5OSwvsDdXdQo0jtHOaiHJXw4WxvdzM2EjcoblAQFjx
9mmDAY6RrIjoY6hhg902NqP9zMAr32DLzeZyrPvIAOtP44PJidv3mxWp2g92Zbx9
EB8XZ6EpYhwrXOhM1NlJYiFEPCiawiTQdShrIN/9uHI0eJeql/xN5mjvPUEchojf
Qur4Hb0ocmu6Rffy0yxKo1P3H5z0y6iZV+ovEWxZoFG6/mdO51nyzmAk5V9fD/Bz
/4ef1hxm7WCsjU4mUNOFQAYsTlsQBgFVWLe5WUGLAdGwjSWzzRHOV0Q8LHAuWhdF
YpTUYEt0sgik76lLGK3RzLql2X+cbzfHNC0akQIDAQABAoIBAGNNWGCcFVz5nqi1
E3mzmzM99GGwpHdSiXz4vXa/W4P40QxrzJbzHjrlGJ7njKLSRjNwawN17H1Touof
2DsUwYMWjECUYV8UR3RJ9NRnNazZMmwTRdXG6puwjeOC52P4nrKbNbh9r1pbwoJ2
lvsInmq7CXnN6kJMFiNWL6VH9CVk4GX9A2F86BiRbnCUjrY75kA+iOdjyA6FpaNL
1j47ZfbB4K9zmfx/pyUoV5LYBKejkeWqnxl8jvRaHCbm6MLDYOMsGNvHkimUI1J0
zYJ53zSByRABl7fFlLCGuGD19dr5Hjn1Jl19AeqwlDplAa8zYhennoA4U81PqRmu
gTvqZgECgYEA3sRjUHCV04MvaUkLYJkNZiNM1EylE8DFu5tqhjzT2/Hm0wvJd+uH
EeoihMG0R83lL9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