如何以安全的方式使用便携式外壳创建临时文件? [英] How to create a temporary file with portable shell in a secure way?
本文介绍了如何以安全的方式使用便携式外壳创建临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在POSIX shell(/bin/sh
)中创建一个临时文件.
I want to create a temporary file in POSIX shell (/bin/sh
).
我发现mktemp(1)
在我的AIX盒子上不存在,并且根据如何便携是mktemp(1)吗?,那不是便携性和/或安全性.
I found out that mktemp(1)
doens't exist on my AIX box, and according to How portable is mktemp(1)?, it isn't that portable and/or secure anyway.
那么,我应该改用什么呢?
So, what should I use instead ?
推荐答案
为什么不使用/dev/random
?
使用perl可能会更整洁,但是od和awk可以,例如:
It could be neater with perl but od and awk will do, something like:
tempfile=XXX-$(od -N4 -tu /dev/random | awk 'NR==1 {print $2} {}')
这篇关于如何以安全的方式使用便携式外壳创建临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文