linux的几种基操

Linux服务器连接另一个linux服务器

ssh [email protected]//登录
exit //登出

在服务器集群环境中,通过ssh免密码登录

ssh会产生私钥和公钥,对方通过公钥进行加密字符串,然后通过私钥进行解密
在本机生成密钥

[root@iZdpqkd3lvx9ncZ ~]# 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: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oZ1x3AP1WHCIdxufM35SSeBUPDMMqbKzPr/1hV6mmy0 root@iZdpqkd3lvx9ncZ
The key's randomart image is:
+---[RSA 2048]----+
|          .oo*X. |
|         ..o=*oB |
|        o o.=oo+*|
|       o * . ..=o|
|      . S o   ..o|
|         o    .o.|
|          o  ...=|
|         o  ..E*.|
|        ..oo. =+.|
+----[SHA256]-----+
[root@iZdpqkd3lvx9ncZ ~]# ls
[root@iZdpqkd3lvx9ncZ ~]# ls -a
.   .bash_history  .bash_profile  .cache  .oracle_jre_usage  .pydistutils.cfg  .tcshrc
..  .bash_logout   .bashrc        .cshrc  .pip               .ssh
[root@iZdpqkd3lvx9ncZ ~]# cd .ssh/
[root@iZdpqkd3lvx9ncZ .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub
[root@iZdpqkd3lvx9ncZ .ssh]# ll
total 8
-rw------- 1 root root    0 Jun 20 17:22 authorized_keys
-rw------- 1 root root 1679 Jul 16 13:33 id_rsa  //密钥
-rw-r--r-- 1 root root  402 Jul 16 13:33 id_rsa.pub //公钥

这里需要注意的是,如果是亚马逊云的服务器,那么通过命令ssh-keygen不一定生成的是RSA的密钥,应当进行指定

ssh-keygen -t dsa 
ssh-keygen -t rsa

ssh提供的拷贝方法

拷贝文件

scp abc.txt [email protected]:/root

拷贝文件夹aaa

scp -r aaa/ [email protected]:/root

把公钥传送到其他服务器

ssh-copy-id [email protected]

接着会输入密码
再使用

ssh [email protected]

时就不用输入密码了

ssh执行命令

ssh [email protected] "echo hello > /root/test.txt"

yum工具

搜索

yum list | grep jdk

shell编程

新建一个hello.sh文件
编码

#!/bin/bash
echo "hello world"

运行方式1

[root@iZdpqkd3lvx9ncZ ~]# sh hello.sh 
hello world

运行方式2

[root@iZdpqkd3lvx9ncZ ~]# chmod +x hello.sh 
[root@iZdpqkd3lvx9ncZ ~]# ./hello.sh
hello world
[root@iZdpqkd3lvx9ncZ ~]# 

编码2

#!/bin/bash
read -p "please input yuor name:" NAME
if [ $NAME = ROOT ]
then
        echo "hello ${NAME},welcome!"
elif[ $NAME = test ]
        echo "hello ${NAME},welcome!"
else
        echo "what 's you say?"
fi

输出

[root@iZdpqkd3lvx9ncZ ~]# ./hello.sh
please input yuor name:ROOT
hello ROOT,welcome!
# GNU/Linux  ssh 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×