方法一:(以OpenSSH编译完成之后的 拷贝和生成key 为例)
#!/bin/bash
DIR_PATH=$HOME/sshdfile
cp sshd $DIR_PATH/sbin
cp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan $DIR_PATH/bin
cp sftp-server ssh-keysign $DIR_PATH/libexec
cp sshd_config ssh_config $DIR_PATH/etc
chmod 755 $DIR_PATH/var/empty
ssh-keygen -t rsa1 -f ssh_host_key -N "" << EOF
y
EOF
ssh-keygen -t rsa -f ssh_host_rsa_key -N "" << EOF
y
EOF
ssh-keygen -t dsa -f ssh_host_dsa_key -N "" << EOF
y
EOF
cp ssh_host_* $DIR_PATH/etc
方法二:(以FTP用户自动登录为例)
#!/usr/bin/expect
set file [lindex $argv 0];
set timeout -1;
spawn ftp 192.168.1.***
expect "Name"
send "username***\r"
expect "Password"
send "passwd***\r"
expect "ftp>"
send "hash\r"
expect "*ftp>*"
send "put $file\n"
expect "*ftp>*"
send "bye\r"
expect "*Goodbye*"
expect eof
exit
【测试】:./autoftp.sh filename
【效果】:自动登陆FTP用户”username***“, 将”filename“ 文件上传至服务器。