ssh with authentication key generation

本文介绍如何通过SSH密钥认证简化服务器登录流程,并利用循环脚本实现对多个服务器的文件传输及软件升级,提高运维效率。

现在要添加ssh的认证密钥免去每次ssh登录服务器要输入用户名和密码

<!-- @page { size: 21.59cm 27.94cm; margin: 2cm } P { margin-bottom: 0.21cm } -->

第一步:生成密匙对,我用的是 rsa的密钥。使用命令 "ssh-keygen -t rsa"

 第二步:把生成的密钥传到你要登录的服务器的 /root/.ssh/authorized_keys

 

scp /root/.ssh/id_rsa.pub root@134.161.1.158:/root/.ssh/authorized_keys

 这样你下次登录对方服务器就可以不需要用户名和密码

下面我们就来讲讲同时对多个服务器进行操作,比如我服务器A上有一个文件包,要传到其他的14个地市服务器

因为现在SSH不需要用户名和密码就可以这样实现

for host in host1 host2 host3 ...
do
scp <filelist> "$host:/path/to/destination"
done
 
for host in 134.165  134.167.4 34.1638  1364.80  1  134.4.180 3.6.131.71 10.1.200  13.72   134.16 17.34  13
436 13.1. ; 
do 
scp /opt/wifioss/node.tgz root@$host:/opt/wifioss/node.tgz;
done

 

 

统一升级地市采集: MY SOLUTION

 

第一:生成上述 rsa的密钥对,并scp到地市的/root/.ssh/authorized_keys中

 

第二:在/etc/hosts中添加对应各地市名陈的host与名陈对应

122.2.2.2      changde
122.3.3.3      zhuzhou
122.4.4.4       changsha
……

 第三:通过循环完成对各个地市的采集补丁升级

 for host in changde changsha chenzhou hengyang huaihua jishou loudi shaoyang xiangtan yiyang yongzhou yueyang zhuzhou; do  ssh $host 'cd /opt/wifioss/node;tar xvf patch0928.tgz;make'; done
地市A日志:src/monet/monet_util.erl
(cd src;make)
make[1]: Entering directory `/opt/wifioss/node/src'
(cd core;make)
make[2]: Entering directory `/opt/wifioss/node/src/core'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/opt/wifioss/node/src/core'
(cd cron;make)
……
地市B日志:
src/monet/monet_util.erl
(cd src;make)
make[1]: Entering directory `/opt/wifioss/node/src'
(cd core;make)
make[2]: Entering directory `/opt/wifioss/node/src/core'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/opt/wifioss/node/src/core'
(cd cron;make)
make[2]: Entering directory `/opt/wifioss/node/src/cron'
……

……

 这样就完成了对14个地市采集补丁的统一升级

### GitHub SSH Key Configuration and Chinese Characters Display Issue Solution When configuring an SSH key on GitHub, encountering issues with Chinese character display can be frustrating. This situation often arises due to encoding mismatches or terminal settings that do not support Unicode properly. To address this issue effectively: Ensure the correct setup of environment variables related to locale settings. Setting `LANG` and `LC_ALL` to a UTF-8 compatible value such as `en_US.UTF-8` ensures proper handling of multibyte characters including Chinese ones[^1]. For generating an SSH key pair specifically under environments where non-ASCII characters might cause problems, using OpenSSH tools with explicit specification of comment field content helps avoid potential garbling during generation process: ```bash ssh-keygen -t ed25519 -C "your_email@example.com" ``` After creating the SSH key, adding it to the ssh-agent enhances security while managing multiple keys efficiently: ```bash eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 ``` Uploading the public part of the newly created SSH key through GitHub's web interface guarantees accurate transmission without corruption from local system configurations. Navigate to Settings -> SSH and GPG keys section within GitHub account controls to complete this step successfully. Verifying connectivity between personal machine and remote servers hosted by GitHub tests whether all previous steps were correctly followed. Executing commands like these provides immediate feedback regarding any remaining discrepancies in configuration: ```bash ssh -T git@github.com ``` A successful connection message indicates everything has been set up appropriately concerning both SSH authentication mechanism and text representation aspects involving international alphabets.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值