本章单独记录在实际应用中使用到ssh的地方
1、ssh的连接失败,用ssh登陆后,很卡,或者ssh登录不上或总是掉线,尝试修改配置文件
解决方案如下:
1、在/etc/ssh/sshd_config 中添加一项:别改错了文件。
UseDNS no
如果每次当输入用户名时弹出Access Denied,
2、继续在/etc/ssh/sshd_config 中修改:
GSSAPIAuthentication no
3、如果还是不行,编辑/etc/ssh/ssh_config,【全局】修改
GSSAPIAuthentication no
4、vi /home/用户名/.ssh/known_hosts
修改存储能ssh服务器对应信息
5、修改etc/hosts.deny
添加一行 sshd:ALL
修改etc/hosts.allow
添加一行 sshd:ALL
6、ssh登录时报以下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
vi /root/.ssh/known_host
删除里面的关于对应ip的这一行
7、配置SSH无密码登陆 # ssh-keygen
[root@test-webgw-1 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 文件名,新手最好默认敲回车
Enter passphrase (empty for no passphrase): #输入公钥密码,免密就敲回车
Enter same passphrase again: #再次输入公钥密码,免密就敲回车
8#根据端口进行ssh登录
# ssh -p 9800 192.168.1.100
9、ssh公钥管理:
ssh-agent bash
输入公钥,免密登录所有设备。
ssh-agent bash
ssh-add .ssh/id_rsa_dg
ssh-add -l
10#批量命令 pssh 操作
#支持pssh命令需要安装pssh的包
yum install -y pssh
批量上传本地文件/mnt/test.file到远程服务器上的/tmp目录:
[root@test-webgw-1]# pscp.pssh -l root -h hosts.txt /mnt/test.file /tmp/
其中hosts.txt 为IP地址存放文件
批量上传本地文件/mnt/test.file、/mnt/aa.file、/mnt/bb.file到远程服务器上的/tmp目录:
[root@test-webgw-1]# pscp.pssh -l root -h hosts.txt /mnt/test.file /mnt/aa.file /mnt/bb.file /tmp/
pssh -h hosts.txt -t 2 -i "uptime"