随笔 - 137  文章 - 1  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿

随笔分类

随笔档案

收藏夹

调试技巧

搜索

  •  

最新评论

阅读排行榜

评论排行榜

strace -o output.txt -c -T -tt -e trace=all -p 28979
posted @ 2020-10-29 16:52 长戟十三千 阅读(309) | 评论 (0)编辑 收藏
#!/bin/sh
if [ $# -lt 3 ];
then
    echo "参数个数错误:log_path dst_path timeout_day, 例子: ./log ./backup 3"
    exit
fi

#策略:3天前移动到备份并压缩

LOG_PATH=$1
DST_PATH=$2
BACKUP_LOG_DATE=`date -d "$3 day ago" +"%Y%m%d"`
echo $LOG_PATH $DST_PATH $BACKUP_LOG_DATE

function FuncTryMkdir()
{
    # 创建备份目录
    if test -d $1
    then
        #echo "已存在目标文件夹:"$1
        return
    else
        mkdir $1
    fi
}

FuncTryMkdir $DST_PATH

#遍历并移动过期日志文件
for FILE_NAME in $LOG_PATH/*
do
    BASE_NAME=`basename $FILE_NAME`
    DATA_DIR=${BASE_NAME:0-11:8}

    #N天前的文件,创建目录,并移动
    if (("$DATA_DIR" < "$BACKUP_LOG_DATE"));then
        BACKUP_DIR=$DST_PATH"/"$DATA_DIR"/"
        FuncTryMkdir $BACKUP_DIR
        mv $FILE_NAME $BACKUP_DIR
    fi
done

#遍历备份并压缩
cd $DST_PATH
for FILE_NAME in ./*
do
    if test -d $FILE_NAME
    then
        BASE_NAME=`basename $FILE_NAME`
        tar czf $BASE_NAME.tar.gz $BASE_NAME
        rm -rf $BASE_NAME
    fi
done
posted @ 2020-10-15 19:01 长戟十三千 阅读(497) | 评论 (0)编辑 收藏
#!/bin/bash
WORK_DIR=`pwd`
FUN_NAME=$1
find $WORK_DIR -name "*.h" -o -name "*.cpp" -o -name "*.c" | xargs grep -n $FUN_NAME
posted @ 2020-10-15 15:40 长戟十三千 阅读(285) | 评论 (0)编辑 收藏
1、描述
接入sdk, libshared.so, 编译时包含了libprotobuf.a, 但本地使用的brpc库,libbrpc.so编译依赖本地libprotobuf.so, 导致冲突
[libprotobuf FATAL google/protobuf/stubs/common.cc:79] This program was compiled against version 2.5.0 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.5.1).  Contact the program author for an update.  If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library.  (Version verification failed in "google/protobuf/descriptor.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  This program was compiled against version 2.5.0 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.5.1).  Contact the program author for an update.  If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library.  (Version verification failed in "google/protobuf/descriptor.pb.cc".)

2、解决
修改libShared.so编译脚本中, 编译依赖库protobuf时,添加命令: -fvisibility=hidden
./configure --with-pic --disable-shared --enable-static "CFLAGS=-fvisibility=hidden"

3、命令:
查询对外符号:
nm -CD libshared.so | grep " T" | grep google
临时添加链接目录:
export LD_LIBRARY_PATH=XXX


trol over symbol exports in GCCaaaa

Control over symbol exports in GCC
posted @ 2020-10-14 17:18 长戟十三千 阅读(3688) | 评论 (0)编辑 收藏

ssh 提供两种级别的安全认证:

  1. 基于口令的安全认证
  2. 基于密钥的安全认证

基于口令的安全认证

需要知道用户名和密码即可登录,该连接是加密的,但客户端不能确认目标主机是否为“伪造的”,也不能保证口令安全。

远程主机的 /etc/ssh/sshd_config 需配置:

PasswordAuthentication yes 

重启 sshd 使改动生效:

$ /etc/init.d/sshd reload 

基于密钥的安全认证

需要用户持有“公钥/私钥对”,远程服务器持有公钥,本地持有私钥。

客户端向服务器发出请求。服务器收到请求之后,先在用户的主目录下找到该用户的公钥,然后对比用户发送过来的公钥。如果一致,服务器用公钥加密“质询”并发送给客户端。客户端收到“质询”后用私钥解密,再发还给服务器。认证结束。

生成 ssh-key,选加密算法(rsa、dsa),给秘钥命名(可选):

$ ssh-keygen -t rsa -C "name" 

passphrase 是证书口令,以加强安全性,避免证书被恶意复制。

会在 ~.ssh 下生成 id_rsa, id_rsa.pub 两个文件,分别是 私钥/公钥。

公钥需保存到远程服务器 ~/.ssh/authorized_keys 里,私钥由客户端本地留存。

要保证 .sshauthorized_keys 都只有用户自己有写权限。否则验证无效。

$ chmod -R 700 ~/.ssh/ $ chmod 600 ~/.ssh/authorized_keys 

ssh 配置的一些实践

$ vim /etc/ssh/sshd_config  # 禁用root账户登录,非必要,但为了安全性,请配置 PermitRootLogin no  # 是否让 sshd 去检查用户家目录或相关档案的权限数据,这是为了担心使用者将某些重要档案的权限设错,可能会导致一些问题所致。例如使用者的 ~/.ssh/ 权限设错时,某些特殊情况下会不许用户登入 StrictModes no  # 是否允许用户自行使用成对的密钥系统进行登入行为,仅针对 version 2。至于自制的公钥数据就放置于用户家目录下的 .ssh/authorized_keys 内 RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys  # 有了证书登录了,就禁用密码登录吧,安全要紧 PasswordAuthentication no 

持有多个 ssh-key 时的使用方法

简单情况下,通过手动指定私钥文件登录

$ ssh username@hostname -i ~/.ssh/my_id_rsa 

觉得麻烦可以配置客户端的 /etc/ssh/ssh_config

# 其实默认 id_rsa 已经加入私钥路径了,这里只是示范 IdentityFile ~/.ssh/id_rsa # 如果有其他的私钥,再加入其他私钥的路径 IdentityFile ~/.ssh/my_id_rsa 

你也可以使用 SSH Agent,下面以使用 GitHub 为场景简单介绍。

$ ssh-keygen -t rsa -C 'second@mail.com' $ ssh-add ~/.ssh/id_rsa_second 

创建 ~/.ssh/config

# Default github user(first@mail.com) Host github.com HostName github.com User git IdentityFile C:/Users/username/.ssh/id_rsa  # second user(second@mail.com) Host github-second HostName github.com User git IdentityFile C:/Users/username/.ssh/id_rsa_second 

配置完成后,在连接非默认账号的仓库时,远端地址要修改为

git remote add test git@github-second:second/test.git # 原来是 git@github.com:second/test.git # git 根据配置的 user.email 来获取 github 帐号来显示 author 信息,记得将 user.email 改为相应的 email


作者:字母数字或汉字
链接:https://www.jianshu.com/p/fab3252b3192
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2020-10-13 16:29 长戟十三千 阅读(501) | 评论 (0)编辑 收藏
     摘要: 之前介绍了使用libcurl的HTTP GET将url地址中内容下载到本地 C/C++中libcurl的使用-Http GET方法使用详解,在更早的文章Linux下使用CURL模拟用户提交post表单中也介绍过在Linux环境使用curl命令提交POST表单。本文介绍使用libcurl的HTTP POST实现表单的提交,并获取表单的结果。libcurl的相关接口已经在上一篇文章中介绍,本...  阅读全文
posted @ 2020-09-08 19:41 长戟十三千 阅读(1036) | 评论 (0)编辑 收藏

在 Linux 系统下如何通过 SSH 密钥来连接 GitHub (Mac系统下设置方法相同)。

引申


Ubuntu 系统初始化配置git环境

测试系统版本 : Ubuntu 16.04 LTS

更新软件源
1
2
3
$ echo "deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list
安装git依赖
1
2
$ apt-get update
$ apt-get install git
设置时区
1
2
3
$ ln -sf /usr/share/zoneinfo/Asia/ShangHai /etc/localtime
$ echo "Asia/Shanghai" > /etc/timezone
$ dpkg-reconfigure -f noninteractive tzdata

Alpine 系统初始化配置git环境

测试系统版本 : Alpine 3.5

更新软件源
1
2
$ echo "http://dl-4.alpinelinux.org/alpine/v3.5/main" >> /etc/apk/repositories
$ echo "http://dl-4.alpinelinux.org/alpine/v3.5/community" >> /etc/apk/repositories
安装依赖

The ssh-keygen command is part of OpenSSH (package “openssh”).

1
2
$ apk update
$ apk add git openssh
设置时区
1
2
3
$ apk add tzdata
$ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
$ echo "Asia/Shanghai" > /etc/timezone

Mac 系统初始化配置git环境

Mac系统上安装git,可以直接从git网站下载安装包,访问 Git - Downloads 安装.

也可以通过 homebrew 进行安装:

1
$ brew install git

设置git账户

执行如下两条命令设置git账户的用户名和密码:

1
2
3
4
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@domain.com"

$ git config --list

生成SSH公钥

SSH 公钥默认储存在账户的主目录下的 ~/.ssh 目录。先确认是否已经有一个公钥了:

1
2
$ cd ~/.ssh
/bin/sh: cd: can't cd to /root/.ssh

主要是看是否存在 id_dsa 或 id_rsa 文件。有 .pub 后缀的文件就是 公钥,另一个文件则是密钥。

创建新的SSH密钥

如果已经存在公钥,可跳过这步。如果没有,使用 ssh-keygen 来创建:

1
2
$ cd ~
$ ssh-keygen -t rsa -C "youremail@domain.com"

示例:(xxxxxx@126.com 为我的账户邮箱)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
~ # ssh-keygen -t rsa -C "xxxxxx@126.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): # 直接回车,则将密钥按默认路径及文件名进行存储。此时也可以输入特定的文件名
Created directory '/root/.ssh'.
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:yFt14TcP0H+ixy9VKiILPPJ6DVevkKgrbxVFqk7mn5k xxxxxx@126.com
The key's randomart image is:
+---[RSA 2048]----+
| o. |
| . . o. |
| o . o +. |
| .... ... ..++|
| . o .So . o+|
| + o Bo= . + + .|
| = *.* + o o |
| ++o o o . . .|
| E=++ . |
+----[SHA256]-----+

查看生成的文件:

1
2
3
$ cd ~/.ssh
~/.ssh $ ls
id_rsa id_rsa.pub

文件 id_rsa.pub 就是公钥。


在 GibHub 中添加你的公钥

复制公钥 id_rsa.pub 文件中的内容。

我这里使用 XShell 来登录的linux服务器,可以直接复制出来。或在 vim 下,可通过命令 ggVG 全选,+y 复制选中内容到+寄存器,也就是系统的剪贴板,供其他程序使用。

登陆Github网站,选择 Settings –> SSH and GPG keys 菜单,点击 New SSH key 按钮。
粘贴你的密钥到 Key 输入框中并设置 Title 信息,点击 Add SSH key 按钮完成。


连接测试

测试 SSH keys 是否设置成功,执行如下命令:

1
$ ssh -T git@github.com

当提示如下信息时,说明正常连通了github:

1
Hi xxxxxx! You've successfully authenticated, but GitHub does not provide shell access.

如果你是第一次设置连接github.com,会询问你是否继续,输入 yes 即可,这样就会将连接地址记录在本地:

1
2
3
4
5
6
$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpxxxxxxxxARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Hi xxxxxx! You've successfully authenticated, but GitHub does not provide shell access.

然后就可以将本地的项目用github来管理了。


更新日志

  • 2017-10-27 - 完善”连接测试”内容; 添加Mac系统下安装git配置
如有疑问或需要技术讨论,请留言或发邮件到 service@itfanr.cc
posted @ 2020-09-03 11:26 长戟十三千 阅读(420) | 评论 (0)编辑 收藏
     摘要: LZ4 (Extremely Fast Compression algorithm)项目:http://code.google.com/p/lz4/作者:Yann Collet本文作者:zhangskd @ csdn blog 简介 LZ4 is a very fast lossless compression algorithm, providing compres...  阅读全文
posted @ 2020-08-14 15:57 长戟十三千 阅读(2098) | 评论 (0)编辑 收藏

openssl官网:https://www.openssl.org

下载源码

源码地址为:https://www.openssl.org/source/old/;当前最新版本为 1.1.0f,https://www.openssl.org/source/old/1.1.0/openssl-1.1.0f.tar.gz

源码编译

解压之后,进入源码目录openssl-1.1.0f,执行如下命令。因为只需要编译静态库,也没有特殊要求,所以使用的编译选项配置很简单:

./config -fPIC no-shared --prefix=/home/aa/Downloads/linux

make all

make install

--prefix  用来指定输出目录  ,-fPIC:指示生成位置无关的代码,这个选项是在把openssl生成的静态库链接到动态库的时候提示错误添加的;no-shared:指示生成静态库。

最终在指定目录下会编译出libssl.a和libcrypto.a两个库文件,在开发的时候只需要包含头件并链接这两个库就可以了。

 

附录:

关于openssl的编译选项的解读:

全局选项

第一类是全局性选项:

--openssldir=OPENSSLDIR 安装目录,默认是 /usr/local/ssl 。

--prefix=PREFIX 设置 lib include bin 目录的前缀,默认为 OPENSSLDIR 目录。

--install_prefix=DESTDIR 设置安装时以此目录作为"根"目录,通常用于打包,默认为空。

zlib
zlib-dynamic
no-zlib 使用静态的zlib压缩库、使用动态的zlib压缩库、不使用zlib压缩功能。

threads
no-threads 是否编译支持多线程的库。默认支持。

shared
no-shared 是否生成动态连接库。

asm
no-asm 是否在编译过程中使用汇编代码加快编译过程。

enable-sse2
no-sse2 启用/禁用SSE2指令集加速。如果你的CPU支持SSE2指令集,就可以打开,否则就要关闭。

gmp
no-gmp 启用/禁用GMP库

rfc3779
no-rfc3779 启用/禁用实现X509v3证书的IP地址扩展

krb5
no-krb5 启用/禁用 Kerberos 5 支持

ssl
no-ssl
ssl2
ssl3
no-ssl2
no-ssl3
tls
no-tls 启用/禁用 SSL(包含了SSL2/SSL3) TLS 协议支持。

dso
no-dso 启用/禁用调用其它动态链接库的功能。[提示]no-dso仅在no-shared的前提下可用。

[提示]为了安装Apache的mod_ssl成功,SSLv2/SSLv3/TLS都必须开启。

算法选项

第二类用于禁用crypto目录下相应的子目录(主要是各种算法)。虽然理论上这些子目录都可以通过"no-*"语法禁用,但是实际上,为了能够最小安装libcrypto,libssl,openssl,其中的大部分目录都必须保留,实际可选的目录仅有如下这些:

no-md2,no-md4,no-mdc2,no-ripemd 这些都是摘要算法,含义一目了然。

no-des,no-rc2,no-rc4,no-rc5,no-idea,no-bf,no-cast,no-camellia 这些都是对称加密算法,含义一目了然。"bf"是"Blowfish"的意思。

no-ec,no-dsa,no-ecdsa,no-dh,no-ecdh 这些都是不对称加密算法,含义一目了然。

no-comp 数据压缩算法。因为目前实际上并没有压缩算法,所以只是定义了一些空接口。

no-store 对象存储功能。

 

CURL

   https://curl.haxx.se/download/curl-7.61.0.tar.gz

1.下载,解压;进入目录;将上面openssl 输出的整个目录,命名 openssl 拷贝到 curl 目录下;

2.编译:

 ./configure --prefix=/home/aa/Downloads/linux --with-ssl=$(pwd)/openssl --disable-shared

 

./configure --prefix=/home/program/linux/libs --with-ssl=/usr/local/openssl --disable-shared

 

--prefix指定输出目录;--with-ssl=./openssl 指定 openssl 目录;

make all

make install

openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题

libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3f2): undefined reference to `dlerror'
libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x459): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x4c9): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x502): undefined reference to `dlerror'
libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x5a1): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x601): undefined reference to `dlerror'
libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x662): undefined reference to `dlclose

async.c:(.text+0xe4): undefined reference to `pthread_setspecific'
async.c:(.text+0xf4): undefined reference to `pthread_getspecific'
async.c:(.text+0x104): undefined reference to `pthread_setspecific'
/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_init_thread.part.1':
async.c:(.text+0x253): undefined reference to `pthread_setspecific'
/usr/local/openssl/lib/libcrypto.a(async.o): In function `async_start_func':
async.c:(.text+0x36f): undefined reference to `pthread_getspecific'
async.c:(.text+0x39e): undefined reference to `pthread_getspecific'
/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_start_job':
async.c:(.text+0x404): undefined reference to `pthread_getspecific'
async.c:(.text+0x41e): undefined reference to `pthread_getspecific'
async.c:(.text+0x433): undefined reference to `pthread_getspecific'
/usr/local/openssl/lib/libcrypto.a(async.o):async.c:(.text+0x44c): more undefined references to `pthread_getspecific' follow
/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_start_job':
async.c:(.text+0x7ef): undefined reference to `pthread_setspecific'
async.c:(.text+0x811): undefined reference to `pthread_getspecific'
async.c:(.text+0x82d): undefined reference to `pthread_getspecific'
async.c:(.text+0x83f): undefined reference to `pthread_getspecific'
async.c:(.text+0x870): undefined reference to `pthread_getspecific'
async.c:(.text+0x891): undefined reference to `pthread_getspecific'
/usr/local/openssl/lib/libcrypto.a(async.o):async.c:(.text+0x8a6): more undefined references to `pthread_getspecific' follow
/usr/local/openssl/lib/libcrypto.a(async_posix.o): In function `async_global_init':
async_posix.c:(.text+0xc): undefined reference to `pthread_key_create'
async_posix.c:(.text+0x1e): undefined reference to `pthread_key_create'
/usr/local/openssl/lib/libcrypto.a(async_posix.o): In function `async_local_init':
async_posix.c:(.text+0x3d): undefined reference to `pthread_setspecific'
async_posix.c:(.text+0x50): undefined reference to `pthread_setspecific'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
 

在CMakeList

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -Wall   -std=c++11")

添加 -ldl -lpthread


plus:
curl master: https://github.com/curl/curl.git
cmake3 ../ -DBUILD_SHARED_LIBS=0 -DOPENSSL_ROOT_DIR=/data/code/openssl

posted @ 2020-08-07 16:52 长戟十三千 阅读(1973) | 评论 (0)编辑 收藏

建立PublicKey登陆步骤其实非常简单,总结来说就是将客户端生成的的ssh public key添加到服务器的~/.ssh/authorized_keys文件中,即可实现ssh的免密码登录。

步骤

1.客户端生成公钥和密钥
2.将公钥配置到服务器即可

1.客户端生成公钥和密钥

在客户端生成公钥密钥 附一篇ssh-keygen 基本用法

$ cd .ssh/ $ ssh-keygen -t rsa  -C "My-key" 

然后一路回车, 使用默认值即可

使用ls 命令可以看到当前目录下的文件,有了个 id_rsaid_rsa.pub,前者是密钥,后者是公钥。

 

查看公钥

$ cat id_rsa.pub 

复制公钥

2.将公钥配置到服务器

先尝试进入 .ssh 看看目录是否存在

$ cd .ssh 

若不存在则新建一个

$ mkdir ~/.ssh 

然后修改权限

$ chmod 700 .ssh 

接着再进入.ssh,然后修改将公钥添加到authorized_keys

$ vim authorized_keys 

i,然后将刚刚复制的密钥粘贴到这里,按esc,再按:,输入wq保存并退出
接着修改权限

$ chmod 600 ~/.ssh/* 

做好配置之后,通过ssh可以直接登录了。

简化登陆指令

我们可以利用ssh的配置文件来简化我们登陆的操作
配置文件在~/.ssh/config
我们可以修改这个文件(如果不存在则新建一个)

Host            YourName HostName        YourServer User            root 

YourName可以改成任意名字
如果修改了端口则需要加上Port参数
还有各种各样的参数可以查看帮助

$ man ssh_config 

配置完后可以这样登陆服务器

$ ssh YourName 

Enjoy it~



作者:河里的肥鱼
链接:https://www.jianshu.com/p/1600fbf01917
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2020-06-28 15:52 长戟十三千 阅读(846) | 评论 (0)编辑 收藏
仅列出标题
共14页: 1 2 3 4 5 6 7 8 9 Last