• 使用sshkey,禁用密码登陆,以及git仓库的搭建



    使用sshkey,可以实现免密码登陆服务器,同时关闭ssh service的使用账号密码登陆功能即可

    1、首先在客户机添加sshkey(如果是window系统的话需要安装shell终端工具,例如xshell,gitbash等)

    ssh-keygen -t rsa -C 'email@sample.com'
    
    #之后会在用户目录下生成一个.ssh目录,里面有“id_rsa”私钥(之前的命令生成的rsa算法加密的key)、“id_rsa.pub”公钥,私钥保存在客户端,公钥保存到服务端即可
    

    2、在服务端的对应用户目录下的.ssh/authorized_keys文件下添加客户端的公钥,每行一个即可。如果authorized_keys原来不存在,新建该文件将拷贝内容放入即可(或者在其他用户的.ssh目录下看看有没有)

    3、修改服务端对应用户的相应文件的权限:(改成一致即可,尽量不要多也不要少)

    $ls -la /home/username
    drwx--x--x  9 username username 4096 May 11 10:09 username
    $ls -la /home/username/.ssh
    -rw-r--r-- 1 username username  797 May 11 10:09 authorized_keys
    $ls -la /home/username
    drwx------ 2 username username 4096 May 11 10:09 .ssh
    

    4、关闭ssh server的使用账号密码登陆功能

    修改/etc/ssh/sshd_conf文件,将PasswordAuthentication修改为no

    5、重启ssh service

    sudo service ssh restart
    

    git库的搭建,以上所做的一切都是为了服务于下面的操作

    1、首先,生成一个git仓库

    $ sudo git init --bare test.git
    Initialized empty Git repository in /home/username/test.git/        #提示初始化了一个空的git仓库 
    $ ls test.git
    branches  config  description  HEAD  hooks  info  objects  refs        #该目录下的内容
    $ sudo chown -R username:username test.git        #修改该目录的owner和group为username
    

    2、禁用该用户的shell登陆(前提是这个用户创建就是为了git,不对系统进行登陆)

    修改/etc/passwd

    username:x:1001:1001:,,,:/home/username:/bin/bash
    改为:
    username:x:1001:1001:,,,:/home/username:/usr/bin/git-shell
    

    3、正常使用git

    $ git clone username@server:/home/username/sample.git
    
  • 相关阅读:
    软件工程师的属性与发展
    欢迎使用CSDN-markdown编辑器
    hdu 5446 lucas+crt+按位乘
    poj 2891 模数不互质的中国剩余定理
    3037 插板法+lucas
    poj 1006中国剩余定理模板
    codeforce E
    UVA10820 send a table
    UVA1635 Irrelevant Elements
    uva 10375 Choose and Divide
  • 原文地址:https://www.cnblogs.com/wangjikun/p/6839564.html
Copyright © 2020-2023  润新知