Placeholder Image

字幕列表 影片播放

由 AI 自動生成
  • (techy music)

    (技術性的音樂)

  • - There are times where you may want to host

    - 有的時候,你可能想主持

  • your remote Git repository within your network.

    你的遠程 Git 倉庫在你的網絡中。

  • The reasons for this are varied.

    造成這種情況的原因多種多樣。

  • Perhaps you'll be storing sensitive data

    也許你將存儲敏感數據

  • which you don't want to trust to a cloud provider,

    你不想把這些東西交給一個雲計算供應商。

  • or maybe you want the speed advantage

    或者你想獲得速度上的優勢

  • of having your Git server on your local network.

    在本地網絡上設置Git服務器的做法。

  • I recommend setting up your own private Git repository.

    我建議建立你自己的私人Git倉庫。

  • This way you don't have to worry about

    這樣,你就不必擔心

  • what is being stored in your repository

    在你的存儲庫中存儲了什麼

  • as your repository is private,

    因為你的存儲庫是私有的。

  • nor do you have to worry about storage

    你也不必擔心儲存問題

  • as local storage is large and cheap.

    因為在地存儲量大且便宜。

  • To do this properly, we need two hosts.

    為了正確做到這一點,我們需要兩個主機。

  • I will set this up on my rhhost2 VM

    我將在我的rhhost2虛擬機上設置這個程序

  • and have the rhhost1 client contacted through the network.

    並讓rhhost1的客戶端通過網絡聯繫上。

  • However, this will also work just fine on one host.

    然而,這在一臺主機上也能正常工作。

  • It's just not we'd build it in a real environment.

    只是我們不會在真實環境中建造它。

  • To run it on one host,

    要在一臺主機上運行它。

  • we'll just have the client host

    我們只需讓客戶主機

  • contact itself over the network.

    通過網絡聯繫自己。

  • To create a remote Git repository easily

    要輕鬆創建一個遠程的Git倉庫

  • we'll be using SSH keys,

    我們將使用SSH密鑰。

  • which means you'll probably want a Git repository

    這意味著你可能需要一個Git倉庫

  • on an operating system that has an SSH server

    在一個有SSH服務器的作業系統上。

  • such as Linux, Unix, or macOS.

    如Linux、Unix或macOS。

  • Although it can also work on Windows using Win32_OpenSSH.

    儘管它也可以在Windows上使用Win32_OpenSSH工作。

  • Go to the host with a remote repository will reside,

    轉到遠程版本庫所在的主機。

  • for me, this is rhhost2.

    對我來說,這就是rhhost2。

  • If you plan on doing this exercise on one host,

    如果你打算在一臺主機上做這個練習。

  • just follow along as these instructions will work

    只要按照這些訓示去做就可以了

  • for that scenario as well.

    對這種情況也是如此。

  • Let's start by creating a Git user.

    讓我們從創建一個Git用戶開始。

  • Type in sudo useradd git

    鍵入sudo useradd git

  • and hit enter.

    並點擊回車。

  • Type in your password if prompted.

    如果有提示,請輸入密碼。

  • Now let's give the Git user a password.

    現在讓我們給 Git 用戶一個密碼。

  • Type in sudo passwd git

    鍵入sudo passwd git

  • and hit enter.

    並點擊回車。

  • Now give the Git user a password.

    現在給 Git 用戶一個密碼。

  • Now make a directory for the Git repository.

    現在為 Git 倉庫建立一個目錄。

  • We'll call it GitProjectTwo.git

    我們將其稱為GitProjectTwo.git

  • and place it /srv/git.

    並把它放在/srv/git。

  • Where you put this is not that important,

    你把這個放在哪裡並不那麼重要。

  • as long as the git user has access to it.

    只要git用戶可以訪問它。

  • Type in sudo mkdir -p /srv/git/GitprojectTwo.git

    輸入sudo mkdir -p /srv/git/GitprojectTwo.git

  • Make sure you use the -p option

    請確保你使用-p選項

  • so it creates the parent directories.

    所以它創建了父目錄。

  • Notice that I've used the .git naming convention

    注意,我使用了.git的命名規則

  • for this directory.

    為這個目錄。

  • This is to tell me that this is a remote repository

    這是為了告訴我這是一個遠程倉庫。

  • being served at two other hosts.

    正在為另外兩個主人提供服務。

  • We will not see the into this directory and do commits.

    我們將不會看到進入這個目錄並做提交。

  • Now, change into the GitProject2.git directory by typing in

    現在,在GitProject2.git目錄中鍵入

  • cd /srv/git/GitProjectTwo.git

    cd /srv/git/GitProjectTwo.git

  • and hit enter.

    並點擊回車。

  • Now we'll initialize a bare Git repository.

    現在我們將初始化一個裸露的Git倉庫。

  • Type in sudo git init --bare and hit enter.

    輸入sudo git init --bare,然後點擊回車。

  • That's the basic Git server setup.

    這就是基本的 Git 服務器設置。

  • Now let's set permissions,

    現在我們來設置權限。

  • cd up two levels by typing in cd /srv and hit enter.

    通過輸入cd /srv並點擊回車鍵,cd上升兩級。

  • And we'll change the ownership of the Git directory

    然後我們將改變Git目錄的所有權

  • to the Git user and the Git group.

    到Git用戶和Git組。

  • Type in sudo chown -R git.git git

    鍵入sudo chown -R git.git git

  • and hit enter.

    並點擊回車。

  • All files should now be owned

    現在所有的文件都應該屬於

  • by the Git user and the Git group.

    由Git用戶和Git組決定。

  • Let's verify.

    讓我們來驗證一下。

  • Type in ls -lR git

    鍵入ls -lR git

  • and hit enter.

    並點擊回車。

  • And we can see that they are.

    而我們可以看到,他們是。

  • Before we move to the client,

    在我們轉移到客戶之前。

  • we need to know the IP address of this host.

    我們需要知道該主機的IP地址。

  • Type in clear, and then type in ifconfig, and hit enter.

    鍵入clear,然後鍵入ifconfig,並點擊回車。

  • My IP address is 192.168.1.125.

    我的IP地址是192.168.1.125。

  • Even if you're using one host for this exercise,

    即使你在這個練習中使用一個主機。

  • you'll still need to know the IP address,

    你仍然需要知道IP地址。

  • as you'll still be using it.

    因為你仍然會使用它。

  • Now let's move over to the client host.

    現在讓我們移到客戶主機上。

  • In my case, this is rhhost1.

    在我的例子中,這就是rhhost1。

  • Again, if you're doing this on one host, that's fine,

    同樣,如果你在一臺主機上做這個,這很好。

  • we'll just have our client contact our server,

    我們只是讓我們的客戶聯繫我們的服務器。

  • which happens to be the same host with same IP address.

    這恰好是同一臺主機,有相同的IP地址。

  • Let's create a new local project called GitProjectTwo.

    讓我們創建一個新的在地項目,名為GitProjectTwo。

  • Type in mkdir -p ~/RemoteRepos/GitProjectTwo

    輸入mkdir -p ~/RemoteRepos/GitProjectTwo

  • and hit enter.

    並點擊回車。

  • Notice that I didn't include the .git portion of the name.

    注意,我沒有包括名稱中的.git部分。

  • This tells me this is a Git project directory

    這告訴我這是一個Git項目目錄

  • that I'll cd into and make commits

    我將進入cd並進行提交

  • The naming convention is actually up to you.

    命名方式實際上由你決定。

  • Now change into it,

    現在換上它。

  • type in cd ~/RemoteRepos/GitProjectTwo/

    鍵入cd ~/RemoteRepos/GitProjectTwo/

  • and hit enter.

    並點擊回車。

  • And we'll initialize the repository

    我們將初始化存儲庫

  • by typing git init

    通過輸入git init

  • Now let's copy a few files to it.

    現在讓我們複製一些文件到其中。

  • Type in cp /etc/passwd /etc/hosts /etc/resolv.cof .

    輸入cp /etc/passwd /etc/hosts /etc/resolv.cof 。

  • Make sure you add the . at the end.

    確保你在最後加上.。

  • This has to copy these files to the current directory

    這必須將這些文件複製到當前目錄下

  • which is the GitProjectTwo directory.

    也就是GitProjectTwo的目錄。

  • If you're using an OS without these files

    如果你使用的作業系統沒有這些文件

  • choose some other files to copy.

    選擇一些其他文件進行復制。

  • Now, hit enter.

    現在,點擊回車。

  • Now stage the files for a commit.

    現在,為提交文件做準備。

  • Type in git add .

    鍵入git add .

  • the dot matches all files in the directory.

    點匹配目錄中的所有文件。

  • Go ahead and hit enter.

    繼續按回車鍵。

  • Now we'll commit them with

    現在我們將用以下方式提交它們

  • git commit -m "Initial Commit"

    git commit -m "Init Initial Commit"

  • and hit enter.

    並點擊回車。

  • Now let's add our Git server as a remote.

    現在讓我們把我們的Git服務器添加為一個遠程。

  • For me this would be

    對我來說,這將是

  • git remote add origin git@

    git remote add origin git@

  • and then my IP address of my rhhost2 VM

    然後是我的rhhost2虛擬機的IP地址

  • 192.168.1.125

    192.168.1.125

  • You want to use your IP address here,

    你想在這裡使用你的IP地址。

  • :/srv/git/git/GitProjectTwo.git

    :/srv/git/git/GitProjectTwo.git

  • now press enter.

    現在按回車鍵。

  • Now verify with git remote -v

    現在用git remote -v來驗證

  • and hit enter.

    並點擊回車。

  • We can see that we have one remote host

    我們可以看到,我們有一個遠程主機

  • for fetching and pushing to.

    用於取和推到。

  • Now let's push our files to the remote.

    現在讓我們把我們的文件推送到遠程。

  • git push origin master

    git push origin master

  • and hit enter.

    並點擊回車。

  • Say yes to accept the fingerprint

    說 "是 "以接受指紋

  • and now type in the Git user's password and hit enter.

    現在輸入Git用戶的密碼並點擊回車。

  • If successful, you'll see it in the message on the screen.

    如果成功,你會在螢幕上的資訊中看到。

  • Now other hosts can clone this repository

    現在其他主機可以克隆這個版本庫了

  • by tipping and get clone followed by the same URL.

    通過小費,得到克隆後的相同網址。

  • Again, adjust the IP address to match your host.

    同樣,調整IP地址以匹配你的主機。

  • Now, what we want to do is use SSH keys for authentication.

    現在,我們要做的是使用SSH密鑰進行認證。

  • Once this is done, you can commit and push

    一旦完成這些,你就可以提交併推送

  • to the remote repository without being bothered

    到遠程存儲庫而不被打擾

  • with typing in a password,

    與輸入密碼。

  • you will want to be on your Git client.

    你將會希望在你的Git客戶端上。

  • I'm logged into my rhhost1 VM.

    我登錄了我的rhhost1虛擬機。

  • To use SSH keys for authentication,

    要使用SSH密鑰進行認證。

  • we need to create our key pairs on our client

    我們需要在我們的客戶端創建我們的密鑰對

  • and then copy the public key to the Git server.

    然後將公鑰複製到 Git 服務器上。

  • On your client, type in

    在你的客戶端,鍵入

  • ssh -keygen -t rsa -b 4096 -C "

    ssh -keygen -t rsa -b 4096 -C "

  • and then your email address.

    然後是你的電子郵件地址。

  • Be sure to use your email address here.

    請務必在此使用您的電子郵件地址。

  • Also, if you plan on using these keys for GitHub

    另外,如果你打算將這些密鑰用於GitHub

  • make sure the email address will match.

    確保電子郵件地址能夠匹配。

  • Now, hit enter.

    現在,點擊回車。

  • It will ask us the name of the file to save the keys as,

    它將詢問我們要保存鑰匙的文件名。

  • you can take the default here.

    你可以在這裡接受默認。

  • For the passphrase, leave it blank and hit enter twice.

    對於口令,留空,敲兩次回車。

  • We can view the key pair by listing the .ssh directory.

    我們可以通過列出.ssh目錄來查看密鑰對。

  • To have an ls ~/.ssh and hit enter

    要有一個ls ~/.ssh,然後點擊回車鍵

  • We can see that we have an id_rsa key,

    我們可以看到,我們有一個id_rsa鍵。

  • that's our private key and an id_rsa.pub,

    這就是我們的私鑰和一個id_rsa.pub。

  • which is our public key.

    這就是我們的公鑰。

  • Now using the ssh-copy-id command

    現在使用ssh-copy-id命令

  • we can copy the public key to the Git server.

    我們可以把公鑰複製到 Git 服務器上。

  • Type in clear, type in ssh-copy-id git@

    鍵入clear,鍵入ssh-copy-id git@

  • and your get server IP address.

    和你獲得的服務器IP地址。

  • In my case, it's 192.168.1.125

    在我的情況下,它是192.168.1.125

  • You want to make sure you use your IP address here

    你要確保你在這裡使用你的IP地址

  • and hit enter.

    並點擊回車。

  • It will prompt you for the Git password

    它將提示你輸入Git密碼

  • on the get server type that in and hit enter.

    在獲取服務器上鍵入該資訊並點擊回車。

  • If successful, it'll say Number of key(s) added: 1,

    如果成功,它會說添加的鑰匙數量:1。

  • it'll also say to test it.

    它也會說要測試它。

  • Type in ssh git@ and your IP address.

    鍵入ssh git@和你的IP地址。

  • which you see on the screen.

    這是你在螢幕上看到的。

  • Let's go ahead and do that.

    讓我們繼續下去,並做到這一點。

  • Type in ssh git@

    鍵入ssh git@

  • in my case, it's 192.168.1.125

    在我的情況下,它是192.168.1.125

  • and hit enter.

    並點擊回車。

  • And if it's a successful, you can log in

    而如果是成功的,你可以登錄

  • without a password which I did.

    在沒有密碼的情況下,我做到了。

  • Once you've done this, type in exit.

    一旦你完成了這些,就輸入退出。

  • Note, you can do this manually and append this public key

    注意,你可以手動完成這個工作,並附加這個公鑰

  • to the .ssh/authorized_keys file on the remote host,

    到遠程主機上的.ssh/authorized_keys文件。

  • but the ssh_copy_id command takes care of it for us

    但ssh_copy_id命令為我們處理了這個問題。

  • as well as setting permissions.

    以及設置權限。

  • If your operating system has the ssh_copy_id command,

    如果你的作業系統有ssh_copy_id命令。

  • save yourself from trouble and use it.

    拯救自己的麻煩,使用它。

  • You may not want people logging in interactively

    你可能不希望人們以互動方式登錄

  • as the Git user with SSH,

    作為 Git 用戶使用 SSH。

  • so you may want to change the shell

    所以你可能想改變外殼

  • for the Git user to git-shell.

    為Git用戶的git-shell。

  • I won't go into that here, but it's a good idea.

    我不會在這裡討論這個問題,但這是一個好主意。

  • Check the git-shell man page for more information

    查看git-shell手冊以獲得更多資訊

  • I have mentioned that you can also use these keys

    我已經提到,你也可以使用這些鑰匙

  • for the GitHub repository too.

    對GitHub倉庫也是如此。

  • First, let's copy the SSH key into our clipboard.

    首先,讓我們把SSH密鑰複製到我們的剪貼板上。

  • Type in clear, and then type in cat ~/.ssh/id_rsa.pub.

    鍵入clear,然後鍵入cat ~/.ssh/id_rsa.pub。

  • Make sure you have the .pub file as it's the public key.

    請確保你有.pub文件,因為它是公鑰。

  • And then highlight it and copy it into your clipboard.

    然後高亮顯示並將其複製到你的剪貼板。

  • Now bring up a web browser and log into your GitHub account.

    現在調出一個網頁瀏覽器,登錄你的GitHub賬戶。

  • Click on the photo on the top right,

    點擊右上角的照片。

  • and then click on Settings.

    然後點擊設置。

  • In the left hand pane, click on SSH and GPG keys,

    在左邊的窗格中,點擊SSH和GPG密鑰。

  • and then click on New SSH key,

    然後點擊新建SSH密鑰。

  • give it a title,

    給它一個標題。

  • I'm going to call mine rhhost1

    我打算把我的稱為rhhost1

  • and then paste the key into the next box.

    然後將鑰匙粘貼到下一個框中。

  • And then lastly, click on, Add SSH key.

    然後,最後點擊,添加SSH密鑰。

  • Now the key is on GitHub.

    現在鑰匙在GitHub上。

  • The last thing we need to do is change our remotes

    我們需要做的最後一件事是改變我們的遙控器

  • from HTTPS to the Git protocol,

    從HTTPS到Git協議。

  • click on the GitHub logo and then click on your repository,

    點擊GitHub標誌,然後點擊你的倉庫。

  • and then click on Clone or download

    然後點擊克隆或下載

  • and click on Use SSH.

    並點擊使用SSH。

  • You want a copy that URL into your clipboard.

    你要把這個URL複製到你的剪貼板上。

  • Now go back to your terminal,

    現在回到你的終端。

  • type in clear, and then change into your

    鍵入清晰,然後換上你的

  • GitProjectOne directory.

    GitProjectOne目錄。

  • Type in cd GitProjectOne/ and hit enter.

    輸入cd GitProjectOne/,然後點擊回車。

  • And let's look at the remotes,

    我們再來看看遙控器。

  • type in git remote -v and hit enter.

    輸入git remote -v並點擊回車。

  • You'll notice that both remotes use the HTTPS protocol.

    你會注意到,這兩個遙控器都使用HTTPS協議。

  • We want to change this to Git.

    我們想把它改成Git。

  • type in git remote set-url origin

    鍵入git remote set-url origin

  • and then paste the URL you copied from GitHub and hit enter.

    然後粘貼你從GitHub複製的URL並點擊回車。

  • And we can verify with git remote -v and hit enter.

    我們可以用git remote -v來驗證,然後點擊回車。

  • You could also test it by committing a change

    你也可以通過提交一個變化來測試它

  • and trying to push it.

    並試圖推動它。

  • (pleasant music)

    (愉快的音樂)

(techy music)

(技術性的音樂)

字幕與單字
由 AI 自動生成

單字即點即查 點擊單字可以查詢單字解釋