美文网首页
linux的几种基操

linux的几种基操

作者: 织雾呀 | 来源:发表于2019-07-16 17:58 被阅读0次

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

ssh root@192.168.0.30//登录
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 root@192.168.0.30:/root

拷贝文件夹aaa

scp -r aaa/ root@192.168.0.30:/root

把公钥传送到其他服务器

ssh-copy-id root@192.168.0.30

接着会输入密码
再使用

ssh root@192.168.0.30

时就不用输入密码了

ssh执行命令

ssh root@192.168.0.30 "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!

相关文章

  • linux的几种基操

    Linux服务器连接另一个linux服务器 在服务器集群环境中,通过ssh免密码登录 ssh会产生私钥和公钥,对方...

  • 学习小组Day2笔记之linux基础知识学习-潜

    了解linux 接触linux的几种渠道:思维导图来展示 参考链接: 第九期Day2 召唤Linux linux基...

  • MONGODB基操

    增 db.colname.insert() 删 db.colname.remove() 改 db.colname....

  • MYSQL基操

    sudo service musql start 启动mysql mysql -u root -p 输入密码,进入...

  • vim基操

    推出 q:退出q!:如果对文件作了修改,无法用 q 退出,此时 q! 表示丢弃修改并退出x...

  • photoshop基操

    修改标尺单位ctrl+r 显示隐藏标尺 图片放大缩小(ctrl+-、alt滑轮)左右移动(ctrl滑轮) 隐藏显示...

  • git基操

    一.git 简介 git官方文档-中文版 区块解释工作区:就是你现在写代码的地方,暂存区:在工作区修改的记录保存的...

  • pyinstaller基操

  • linux安装软件

    linux安装软件的几种方法

  • 2022-12-27

    基围虾的做法有几种哪种最好吃 基围虾的做法有5种,煎、炸、炒、焖、水煮、凉拌,最好吃的有以下几种: 一、炒蒜香基围...

网友评论

      本文标题:linux的几种基操

      本文链接:https://www.haomeiwen.com/subject/fwgzkctx.html