sidney@ubuntu:~$ sudo passwd root # 设置一次密码就好了 以后就可以用su切换root了 [sudo] password for sidney: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully sidney@ubuntu:~$
1.2 创建git用户
为了不影响当前的环境,我们先创建一个git用户,这个git也可以换成其他喜欢的字符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
sidney@ubuntu:~$ sudo adduser git Adding user `git' ... Adding new group `git' (1001) ... Adding new user `git' (1001) with group `git' ... Creating home directory `/home/git' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for git Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y sidney@ubuntu:~$
sidney@ubuntu:~$ sudo apt-get install git # 安装git 我安装过了 所以结果不一样 Reading package lists... Done Building dependency tree Reading state information... Done git is already the newest version (1:1.9.1-1ubuntu0.10). 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. sidney@ubuntu:~$ sudo apt-get install openssh-server # 安装openssh-server Reading package lists... Done Building dependency tree Reading state information... Done openssh-server is already the newest version (1:6.6p1-2ubuntu2.13). 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. sidney@ubuntu:~$ ssh-keygen # 生成公钥 这个我也生成过了.. Generating public/private rsa key pair. Enter file inwhich to save the key (/home/sidney/.ssh/id_rsa): /home/sidney/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/sidney/.ssh/id_rsa. Your public key has been saved in /home/sidney/.ssh/id_rsa.pub. The key fingerprint is: cd:f8:18:9a:8b:de:91:d0:e0:ce:d3:5c:93:5a:37:dc sidney@ubuntu The key's randomart image is: +--[ RSA 2048]----+ | | | | | . | | . o * . | | o . S * E | | o + B * . | | + O . . | | + o | | .o o | +-----------------+ sidney@ubuntu:~$ sudo vim /etc/ssh/ssh_config # 大概在39行 把Port 22注释打开 默认端口 sidney@ubuntu:~$ sudo /etc/init.d/ssh stop # 重启一下ssh服务 [ ok ] Stopping ssh (via systemctl): ssh.service. sidney@ubuntu:~$ sudo /etc/init.d/ssh start [ ok ] Starting ssh (via systemctl): ssh.service. sidney@ubuntu:~$
sidney@ubuntu:~$ su git # 切换用户 Password: git@ubuntu:/home/sidney$ cd ~ # 进入git的home目录 git@ubuntu:~$ ll git.zip -rw-r--r-- 1 root root 96128663 Jun 21 00:20 git.zip git@ubuntu:~$ sudo chmod 666 git.zip # 改变模式失败.. [sudo] password for git: git is not in the sudoers file. This incident will be reported. git@ubuntu:~$
在git中调用sudo,不出意外都会报这个错的git is not in the sudoers file. This incident will be reported.,接下来的操作,**一定要确保root有密码!一定要确保root有密码!一定要确保root有密码!**
sidney@ubuntu:~$ cd Downloads/ # 克隆仓库 没有问题.. sidney@ubuntu:~/Downloads$ git clone git@192.168.1.109:/home/git/book.git Cloning into 'book'... remote: Counting objects: 46, done. remote: Compressing objects: 100% (35/35), done. remote: Total 46 (delta 11), reused 0 (delta 0) Receiving objects: 100% (46/46), 4.94 KiB | 0 bytes/s, done. Resolving deltas: 100% (11/11), done. Checking connectivity... done. sidney@ubuntu:~/Downloads$ cd book/ sidney@ubuntu:~/Downloads/book$ ls ch1 GLOSSARY.md last_ch README.md SUMMARY.md sidney@ubuntu:~/Downloads/book$ vim README.md # 修改README.md sidney@ubuntu:~/Downloads/book$ git status On branch master Your branch is up-to-date with 'origin/master'.
Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a") sidney@ubuntu:~/Downloads/book$ git diff diff --git a/README.md b/README.md index aae20fc..a35bf2b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Introduction +我是最棒的! just for a test.. test2.. sidney@ubuntu:~/Downloads/book$ git add README.md sidney@ubuntu:~/Downloads/book$ git commit -m "test" [master 7f99d72] test 1 file changed, 1 insertion(+) sidney@ubuntu:~/Downloads/book$ git push origin master # 推也没问题 Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 366 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To git@192.168.1.109:/home/git/book.git 3906bd7..7f99d72 master -> master sidney@ubuntu:~/Downloads/book$ git pull origin master # 拉代码也没问题 From 192.168.1.109:/home/git/book * branch master -> FETCH_HEAD Already up-to-date. sidney@ubuntu:~/Downloads/book$