分类目录归档:Linux

md5&sha 的使用


md5&sha 生成和校验

以sha512sum 为例

sha512sum filename

$ sha512sum ls
ef73136452875c4cae5c6b43117c601ec679f027a4ff1c285d477ab6a8950edb9f8da0822a57b1c0eb719d563cb2033765cdf6c949e9df073fbf7772bf5fad71  ls

$ sha512sum ls > ls.sha512

$ sha512sum -c ls.sha512 
ls: OK

Read more

su 和 sudo 无密码


sudo 无密码

切换到root或者使用sudo 打开/etc/sudoers 添加一行:yourname ALL=(ALL) NOPASSWD: ALL

su 无密码

  1. 切换到root权限;
  2. 创建group为wheel,命令为groupadd wheel;
  3. 将用户加入wheel group中,命令为usermod -G wheel joe;
  4. 修改su的配置文件/etc/pam.d/su,增加下列项: auth required pam_wheel.so group=wheel # Uncomment this if you want wheel member

Read more

SUID、SGID 和SBIT


SUID SGID

针对二进制文件 setuid(set uid ID upon execution) 让执行该二进制文件的用户有持有该文件的用户的权限

ll /bin/passwd 
-rwsr-xr-x 1 root root 27856 Apr  1 11:57 /bin/passwd

SUID -> 4
SGID -> 2
SBIT -> 1
chmod 4755 filename
chmod u+s testfile
chmod g+s testdir
chmod o+t testdir

setgid(set group ID upon execution)

Read more

IPC共享内存


IPC共享内存涉及到的函数


int shmget(key_t key, size_t size, int shmflg);

该函数用来创建共享内存
第一个参数,与信号量的semget函数一样,程序需要提供一个参数key(非0整数),它有效地为共享内存段命名,
shmget函数成功时返回一个与key相关的共享内存标识符(非负整数),用于后续的共享内存函数。调用失败返回-1.
第二个参数,size以字节为单位指定需要共享的内存容量
第三个参数,shmflg是权限标志,它的作用与open函数的mode参数一样,如果要想在key标识的共享内存不存在时,
创建它的话,可以与IPC_CREAT做

Read more

dup、 dup2 和dup3


简介


#include <unistd.h>
int dup(int oldfd);
int dup2(int oldfd, int newfd);
int dup3(int oldfd, int newfd, int flags); // 是GNU的扩展,不一定所有系统都支持

// 这些系统调用都返回oldfd的文件描述符的副本
These system calls create a copy of the file descriptor oldfd.

// 新的文件描述符使用未用的最小的文件描述符
dup() uses the lowest-numbered unu

Read more

getopt and getopts


getopt and getopts

./test.sh -f abc -v --flag true

手工处理

$0 : ./test.sh,即命令本身,相当于C/C++中的argv[0]
$1 : -f,第一个参数
$2 : abc
$3, $4 ... :类推。
$#  : 参数的个数,不包括命令本身,上例中$#为4.
$@ : 参数本身的列表,也不包括命令本身,如上例为 -f abc -v --flag true
$*   : 和$@相同,但"$*" 和 "$@"(加引号)并不同,"$*"将所有的参数解释成一个字符串,而"$@"是一个参数数组

getopts

#!/bin/bash
wh

Read more

pdsh 使用


pdsh 使用教程

Usage: pdsh [-options] command ...
-S                return largest of remote command return values
-h                output usage menu and quit
-V                output version information and quit
-q                list the option settings and quit
-b                disable ^C status fea

Read more