终端脚本

时间:2012-11-08 08:45:05

标签: macos unix terminal

我想在运行脚本后编写一个脚本,通过我的id(两层身份验证)连接到我的服务器。

ssh id@server->password

在此身份验证之后再增加一次身份验证超级用户身份验证

username :

password :

我的操作系统是MAC。

1 个答案:

答案 0 :(得分:0)

要使一切正确,这将是“正常工作”的伎俩。最难记录的问题是对登录目录,.ssh目录和.ssh目录中的文件的正确保护。这是我用来正确设置所有内容的脚本:

#!/bin/tcsh -x
#
# sshkeygen.sh
#

# make sure your login directory has the right permissions
chmod 755 ~

# make sure your .ssh dir exists and has the right permissions
mkdir -pv -m 700 ~/.ssh
chmod 0700 ~/.ssh

# remove any existing rsa/dsa keys
rm -f ~/.ssh/id_rsa* ~/.ssh/id_dsa*

# if your ssh keys don't exist
set keyname = "`whoami`_at_`hostname`-id_rsa"
echo "keyname: $keyname"

if( ! -e ~/.ssh/$keyname ) then
    # generate them
    ssh-keygen -b 1024 -t rsa -f ~/.ssh/$keyname -P ''
endif

cd ~/.ssh

# set the permissions
chmod 0700 *id_rsa
chmod 0644 *id_rsa.pub

# create symbolic links to them for the (default) id_rsa files
ln -sf $keyname     id_rsa
ln -sf $keyname.pub id_rsa.pub

我有另一个脚本将“whoami at hostname - id_rsa.pub”文件复制到共享服务器(作为管理员),然后将其合并到该系统中.ssh / authorized_keys文件,然后将其复制回本地计算机。这些脚本第一次运行时,系统会提示用户输入共享服务器的管理员密码,但之后一切都“正常”。

哦,这是“Mac”(不是“MAC”)。 [\ pedantic]; - )