ssh-批量管理 优化 免秘钥

ssh命令

适用命令及方案如下:
【远程连接及执行命令】

ssh -p22 [email protected].0.0.19

ssh -p22 [email protected].0.0.19 /sbin/ifconfig

【远程拷贝:推送及拉取】

scp -P22 -r -p /etc [email protected].0.0.19:/tmp/

scp -P22 -r -p [email protected].0.0.19:/tmp/ /etc

【安全的FTP功能】

sftp -oPort=22 [email protected].0.0.19

利用ssh-v的调试功能查找慢的原因

windows上传下载需要在CRT文件下找到sftp就可以重本地上传东西了

put 上传

get  下载

检查openssh和openssl是否安装

echo ‘###openssh-openssl###‘1>>~/ssh.ok 2>>ssh.bug

rpm -qa opensshopenssl 1>>~/ssh.ok 2>>ssh.bug

限制外网IP

优化:

以下各项开机时已经实现优化:

Port52113

PermitRootLogin no

PermitEmptyPasswords no

UseDNS no

GSSAPIAuthentication no

只允许内网IP172.16.1.61登录

echo ‘###限制登录内网IP###‘1>>~/ssh.ok 2>>ssh.bug

cp /etc/ssh/sshd_config{,.ssh.ori}

ls /etc/ssh/sshd_config.ssh.ori 1>>~/ssh.ok 2>>ssh.bug

sed -i ‘13a ListenAddress 172.16.1.61:52311‘/etc/ssh/sshd_config

sed -n ‘13,18p‘/etc/ssh/sshd_config 1>>~/ssh.ok 2>>ssh.bug

ssh实现批量管理

一键生成密钥:

法一:

ssh-keygen -t dsa -P ‘‘ -f ~/.ssh/id_dsa >/dev/null 2>&1

法二:

echo -e "\n"|ssh-keygen -t dsa -N ""  >/dev/null 2>&1

echo ‘###查看生成密钥情况###‘1>>~/ssh.ok 2>>ssh.bug

ls -l ~/.ssh 1>>~/ssh.ok 2>>ssh.bug

分发密钥

echo ‘###查看生成密钥情况###‘1>>~/ssh.ok 2>>ssh.bug

ssh-copy-id -i ~/.ssh/id_dsa.pub [email protected] (默认22端口使用)

ssh-copy-id -i ~/.ssh/id_dsa.pub "-p [email protected]"  (改端口使用)

批量分发密钥

批量分发文件

echo ‘###批量分发文件###‘1>>~/ssh.ok 2>>ssh.bug

cat >/home/zhang/scripts/fenfa_file.sh<<EOF

#!/bin/sh

if [ \$# -ne 2 ];then

echo "USAGE:/bin/sh\$0 ARG1 ARG2"

exit 1

fi

. /etc/init.d/functions

for n in 8 31 41

do

scp -P52113 ~/\$1 [email protected].16.1.\${n}:~ >/dev/null 2>&1&&\\

ssh -p52113 -t [email protected].16.1.\$n sudo rsync ~/\$1 \$2 >/dev/null 2>&1

if [ \$? -eq 0 ];then

action "fenfa hosts 172.16.1.\$n" /bin/true

else

action "fenfa hosts 172.16.1.\$n" /bin/false

fi

done

EOF

cat fenfa_file.sh 1>>~/ssh.ok 2>>ssh.bug

批量执行命令

echo ‘###查批量执行命令###‘1>>~/ssh.ok 2>>ssh.bug

cat >/home/zhang/scripts/zhixing.sh<<EOF

#!/bin/sh

if [ \$# -ne 1 ];then

echo "USAGE:/bin/sh \$0 ARG1"

exit 1

fi

for n in 8 31 41

do

echo =======172.16.1.\$n========

ssh -p52113 [email protected].16.1.\$n "\$1"

done

EOF

cat zhixing.sh 1>>~/ssh.ok 2>>ssh.bug

老男孩28期

搭建web01nginx

vim in_nginx.sh

#!/bin/sh

/bin/sh fenfa_file.sh nginx.sh /server/scripts/&&\

/bin/sh zhixing.sh /server/scripts/nginx.sh

vim nginx

#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH

./etc/init.d/functions

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

yum install openssl openssl-devel -y

rpm -qa opensslopenssl-devel

yum install pcre pcre-devel -y

rpm -qa pcre pcre-devel

#######下载nginx并编译安装########

mkdir /install

cd /install

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

useradd www -s /sbin/nologin -M

tar xf nginx-1.6.3.tar.gz

cd nginx-1.6.3

##############配置################

#########检查##########

echo $?

sleep 5

##########编译安装########

make

make install

ln -s /application/nginx-1.6.3//application/nginx

##########启动##########

/application/nginx/sbin/nginx

##########加入到开机启动##########

echo ‘/application/nginx/sbin/nginx‘>>/etc/rc.local

tail -1/etc/rc.local

ps -ef|grep nginx|grep -v grep

sleep 5

##########nginx优化###########

cd /application/nginx/conf/

cat >nginx.conf<<EOF

worker_processes  1;

error_log  logs/error.log;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  main  ‘\$remote_addr - \$remote_user[\$time_local] "\$request" ‘

‘\$status\$body_bytes_sent "\$http_referer" ‘

‘"\$http_user_agent""\$http_x_forwarded_for"‘;

sendfile        on;

keepalive_timeout  65;

include extra/blog.conf;

include extra/status.conf;

}

EOF

mkdir extra

cd extra

cat >blog.conf<<EOF

server {

listen       80;

server_name  blog.etiantian.org;

location /{

root  html/blog;

index index.php index.html index.htm;

}

location ~.*\.(php|php5)?\$ {

root html/blog;

fastcgi_pass 127.0.0.1:9000;

fastcgi_indexindex.php;

include fastcgi.conf;

}

access_log  logs/access_blog.log  main;

}

EOF

cat >status.conf<<EOF

##status

server {

listen       80;

server_name  status.etiantian.org;

location /{

stub_status on;

access_log off;

allow 10.0.0.0/24;

deny all;

}

}

EOF

mkdir /application/nginx/html/blog -p

echo "<\?php phpinfo(); ?>">/application/nginx/html/blog/test_info.php

cat /application/nginx/html/blog/test_info.php

cp /application/nginx/html/index.html/application/nginx/html/blog/

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

[[email protected] scripts]# cat zhixing.sh

#!/bin/sh

if[ $# -ne 1 ];then

echo "USAGE:/bin/sh $0 ARG1"

exit 1

fi

for n in 8

do

echo =======172.16.1.$n========

ssh -t -p52113 [email protected].16.1.$n /bin/sh "$1"

done

[[email protected] scripts]# cat fenfa_file.sh

#!/bin/sh

if[ $# -ne 2 ];then

echo "USAGE:/bin/sh $0 ARG1 ARG2"

exit 1

fi

./etc/init.d/functions

for n in 8

do

scp -P52113 ~/$1 [email protected].16.1.${n}:~>/dev/null 2>&1&&\

ssh -p52113 -t [email protected].16.1.$n sudo rsync ~/$1 $2 >/dev/null 2>&1

if[ $?-eq 0];then

action "fenfa hosts 172.16.1.$n"/bin/true

else

action "fenfa hosts 172.16.1.$n"/bin/false

fi

done

检查

[[email protected] ~]# lsof -i:80

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   4220 root    6u  IPv4  18713      0t0  TCP *:http (LISTEN)

nginx   4235  www    6u  IPv4  18713      0t0  TCP *:http (LISTEN)

时间: 2024-08-03 03:17:21

ssh-批量管理 优化 免秘钥的相关文章

ssh、scp免秘钥远程执行命令:expect

首先安装expect # yum -y install expect 命令格式 # ./expect IP COMM    #expect是独立的工具,所以不能用sh来执行 #!/usr/bin/expect set timeout -1    #超时时间默认10秒,如果你要执行一条很漫长的命令,那么这个很有必要,这里将超时时间设置为永不超时 set COMMADN1 [lindex $argv 0]    #传参变量,这里引用脚本后面的第一个参数 set COMMADN2 [lindex $a

ssh免秘钥登陆实现

1.用处 搭建集群或者工作中登陆跳板机经常需要做免秘钥互相登陆彼此服务器. 2. 准备工作   假设A主机10.20.0.1想通过ssh登录到B主机10.20.0.2上.   那么客户端(A主机)需要安装ssh客户端软件,服务器端(B主机开机sshd进程)需要安装ssh服务器软件.   ssh客户端Linux发行版一般都自带的,对于ssh服务器端,Ubuntu用户可以sudo apt-get install openssh-server来安装,其他Linux用户也安装openssh-server

ssh免秘钥登录

SSH免秘钥登录 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责 [[email protected] ~]# ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):    直接回车Enter passphrase (empty for no passphrase):  直接回车Enter

7)SSH批量管理分发项目

ssh服务认证类型介绍 从SSH客户端来看,SSH服务主要提供两种级别的安全验证,具体级别如下: 基于口令的安全验证: 基于口令的安全验证的方式就是大家一直在用的,只要知道服务器的SSH连接账号和口令,应用服务器的IP及开放的端口,默认为22,就可以通过SSH客户端登录到这台远程主机.此时,联机过程中所有传输的数据都是加密的. 基于口令的我们可以通过expect,pssh,sshpass实现批量管理. 期中集群:一键搭建及优化50台服务器集群 基于密钥的安全验证: 基于密钥的安全验证方式是指,需

linux普通用户免秘钥登陆操作

普通用户(xusj)进行免秘钥登陆步骤如下: 在主机A 192.168.1.1上操作 ssh-keygen -t rsa              //参数公钥和私钥对,输入后一路回车. Generating public/private rsa key pair. Enter file in which to save the key (/home/xusj/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same

Linux之间配置免秘钥访问

环境说明 [[email protected] ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [[email protected] ~]# uname -a Linux localhost1 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux 生成秘钥 [[email protected] ~]# ssh-k

Web集群之SSH批量管理

1.什么是SSH批量管理在管理机产生公钥和私钥,然后把自己的公钥推送给需要被管理的服务器,然后就可以通过scp和ssh命令,无需输入密码即可管理 锁=公钥,钥匙=私钥 企业里实现ssh方案:1)直接root ssh key.条件:系统允许root使用ssh2)sudo提权来实现没有权限用户拷贝 实验环境: hostname ip 描述 m01 172.16.1.61 管理机 web01 172.16.1.7 被管理 nfs 172.16.1.31 被管理 backup 172.16.1.41 被

linux系统下ssh免秘钥登录

我有两台linux主机: 主机名分别是: lsx01.com lsx02.com 希望在lsx01.com这台主机上无秘钥登录lsx02.com. 一.修改hosts文件 在两台机器上都添加主机ip信息 例如在lsx01.com上: vi /etc/hosts 配置如下: 二.生成rsa秘钥文件,统一拷贝至一个authorized_keys中 1.在所有主机上,例如lsx01.com主机上生成rsa秘钥文件 cd /root/.ssh ssh-keygen -t rsa 三下回车 生成了两个文件

免秘钥登录命令

#ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 生成秘钥 #cd ~/.ssh/ id_dsa id_dsa.pub known_hosts id_dsa 私钥(给自己用) id_dsa.pub(给别人用) 把公钥文件追加到本地的认证文件中去 #cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 就可以免密码登录 #scp ./id_dsa.pub [email protected]:/opt 把node1里的公钥