SSH and FTP使用

Lab 1: Working with SSH and FTP software

 

Top of Form

Bottom of Form

  •  

Pre-Lab Tasks

Preliminaries:

    • You are supposed to accomplish the 5 actions in "Required Course Materials". Ask for a help during the class if you have not accomplished it yet.

Definitions:

    • Secure SHell (SSH) is a software to support data transfer between computers and servers. It can be used to support secure logins, file transfers or general purpose connects (More information).
    • A File Transfer Protocol client (FTP client) is a software utility that establishes a connection between a computer and a server in world wide web (More information).

A Short Video:

Please watch the following video.

  •  

Lab 1 - Part 1 (during the class)

Part 1 is worth 5 points and must be submitted in Blackboard by Tuesday, May 21 at 8:00 PM.

Part 1 - Problem 1: Using SSH (Terminal or Secure Shell App) to create folders and files

Step 1: Play around 
 

The first challenge for lab 1 is becoming familiar with SSH commands. You need to use these commands to create a new folder, move between your folders etc... The following is a short list of basic SSH commands:

    • ls           Show directory contents (list the names of files).
    • cd          Change Directory (move forward or backward between folders).
    • mkdir     Create a new folder (short for make directory).
    • touch     Create a new file (such as text files or html files).

Go ahead and log in to your web host by using SSH (ssh Your_BU_UserName@csa1.bu.edu) and try the above commands.

When you put your BU Kerberos, you see something like "-bash-4.2$". Now, you may ask, Where am I? What do I have to do now? No worries! You are in your web host but there is no visual interface. You need to use the commands to see your files and folders. Do the following:

    • Type ls
    • You must be able to see at least one folder called "public_html".
    • Do you want to go inside "public_html" folder? Type cd public_html
    • Now, type ls
    • You probably see nothing or maybe a HTML file with a .html extension.
    • Do you want to create a folder inside "public_html"? type mkdir cs103
    • Now again type ls
    • This time you have to see a folder named "cs103" as one of the files inside "public_html".
    • To go inside "cs103" folder, type cd cs103
    • If you type ls, you will see nothing inside "cs103" because it is empty.
    • OK, lets go back to the "public_html" folder. But how? Type cd ..
    • Now again type ls
    • Do you see only "cs103" folder? Sure do!!!
    • If you want to see this folder in a browser like Firefox, open Firefox and type the following url:
      • http://cs-people.bu.edu/Your_BU_UserName

OK! How was that? Are you excited to continue? I hope you are 

Step 2: The Challenge 
 

Now, I want you to create a text file and name it "my_first_text_by_ssh.txt".

How? You need to do it by yourself!!! The following command might be a good help:

    • touchThis command is used to create a new file with a chosen extension. For example, touch NewFile.txt will create a new txt file named “NewFile” in your current directory (the extension could actually be anything you want, you can even create a new file without extension at all, for example touch NewFile.

Where does this text file need to be placed? Create a new folder inside folder "cs103" and name it "lab1". Go inside "lab1", then create another folder and name it "part1". The "my_first_text_by_ssh.txt" is supposed to be placed inside "part1" folder.

If I want to show you the address of the text file, it is at cs103/lab1/part1

Part 1 - Problem 2: Using FTP software to create folders and files

Step 1: Play around

Open your Filezilla (the FTP software) and log in to your web host. To connect to your web host in the BU CS server, enter the following values. 

    • Host: csa1.bu.edu
    • Username: your BU username.
    • Password: your BU kerberos.
    • Port: 22

As you are supposed to know by now, FileZilla has a left-hand pane which is directories in your computer and a right-hand pane which is your webhost. Go inside folder "public folder". You are supposed to see a folder named "cs103". Yes! Because you made it through SSH. Go inside "cs103" and you will find "lab1" folder, go inside "lab1" and you will find "part1" folder, go inside "part1". Do you see a file named "my_first_text_by_ssh.txt"? Sure do! Now, go back to the "public folder" by double clicking on the very first folder which is named "..". It will help you to go backward to the previous folder. 

Step 2: The Challenge
 

    • In the left-hand pane, find your desktop by clicking on folder "Desktop".
    • Now drag the "my_first_text_by_ssh.txt" from right-hand pane to the left-hand pane.
    • Check the desktop of your computer. You are supposed see the "my_first_text_by_ssh.txt" in the desktop of your computer.
    • Open the txtfile by your text editor (BBEditor Notepad ++) and write down something in the text file (If you are excited write something exciting!!!).
    • Change the name of the text file to "my_first_text_by_ftp.txt".
    • Now drag the "my_first_text_by_ftp.txt" from left-hand pane to the right-hand pane inside a folder at cs103/lab1/part1

Congratulations! You have finished your first CS 103 challenge!!! 

If you want to see your two text files in a browser, type the following url in a browser:

http://cs-people.bu.edu/Your_BU_UserName/lab1/part1

Submit the Assignment

Please prepare your assignment by making the following items in a Microsoft Word document:

    1. Write down your full name and your BU username on top of the page.
    2. Write down the URLs of the two text files that you made and transferred to your web host. One of the URLs should look like the following:

http://cs-people.bu.edu/Your_BU_UserName/cs103/lab1/part1/my_first_text_by_ssh.txt

    1. this document as a PDF file and name it "Lab1-Part1.pdf"
    2. go to Gradescope and submit the PDF file.

Submit a Review

After completion of Lab1-Part1, Please go to this Microsoft Form and give us your answers.

  •  

Lab 1 - Part 2

Part 2 is worth 20 points and must be submitted in Blackboard by Thursday, May 23 at 12:00 PM.

Side Note: This lab assignment includes 13 questions that need to be answered. It is recommended to save a Microsoft Word document in your desktop and type your answers into the document. Then, you can make a PDF file to submit it through Gradescope.

Section 1: Exploring SSH

    • rm – This command is used to remove a chosen file/directory. For example, rm NewFile will remove the previously created file named “NewFile”. If you wish to remove a directory and all the directories inside of it, use rm -r NewFolder, this will delete the folder “NewFolder” and all the other folders inside of it.
      • Log in to your webhost by SSH and go to public_html/cs103/lab1 by using command "cd"
      • Make a directory "part2". Go to "part2" and make a file "test1.txt" and a folder "test1". Go inside folder "test1" and make a file "test2.txt" and a folder "test2".
      • Now, go back to public_html/cs103/lab1/part2
      • Try to remove folder "test1" by using command rm test1
      • Question 1: Can you remove it? If can not, what is the SSH text message?
      • Now, try to remove file "test1.txt" by using command rm test1.txt
      • Question 2: Can you remove it? If can not, what is the SSH text message?
      • Question 3: What is the proper command to remove folder "test2" and all of its belongings?
    • cat – This command is used to display the contents of a file. For example, cat info.txt will bring the contents of the file to the screen. Other example: cat info.txt info2.txt > mergedinfo.txt will merge two files together (“info.txt” and “info2.txt“) and write the merged content to a file “mergedinfo.txt“.
      • Go to public_html/cs103/lab1/part1
      • Bring the contents of the file "my_first_text_by_ftp.txt" to the screen.
      • Question 4: Do you see any text? If no, submit "the text file is empty". If yes, submit the text message as the answer of this question. 
    • pwd – This command shows your current location in the file system.
      • Stay in folder "part1"
      • Type pwd and press enter.
      • Question 5: What is the result? Can you explain it?
    • cp – This command is used to copy files and folders. The syntax is: cp source destination Basically, instead of "source", you write the file which you want to copy. Instead of "destination", write the destination "path/folder/file". Now, if you wrote a destination name which does not exist, for example, you have a source file "oldfile.txt" and write a destination file "newfile.txt", bash will simply copy the file and paste it with a new name.
    • mv – This command works the same way as cp, but instead, it moves the file instead of copying it. This command can also be used to rename the file. If we took the same example from the cp command, (in our current directory, we have one file oldfile.txt) and we write this command: mv oldfile.txt newfile.txt bash will simply rename the file "oldfile.txt" to "newfile.txt".
      • Go to public_html/cs103/lab1/part2
      • Make a folder "test3". Go inside folder "test3" and make a text file "test3.txt".
      • Type cp test3.txt test4.txt
      • Press enter.
      • Now, type mv test3.txt test5.txt
      • Press enter.
      • Question 6: How many files are in folder "test3"? What is/are the file/s?
      • Go to public_html/cs103/lab1/part2
      • Make a file named "test1.txt" if it doesn't exist already.

Section 2: File system security (access rights)

If you go to public_html/cs103/lab1/part2 and type ls -l, you will see that you now get lots of details about the contents of your directory, similar to the example below. Each file (and directory) has associated access rights, which may be found by typing ls -l. For example:

drwxr-xr-x 2 vranjbar cs-faculty 4096 Sep  8 06:50 temp1

In the left-hand side is a 10 symbol string consisting of the symbols d, r, w, x and -. If "d" is present, it will be at the left hand end of the string, and indicates a directory (folder). Otherwise "-" will be the starting symbol of the string showing that it is file not a folder. The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.

    • The left group of 3 gives the file permissions for the user that owns the file (or directory) (vranjbar in the above example);
    • the middle group gives the permissions for the group of people to whom the file (or directory) belongs (cs-faculty in the above example);
    • the rightmost group gives the permissions for all other people in the World Wide Web.

The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or to a directory.

Access rights on files.

    • "r" indicates read permission: the permission to read and copy the file. If you see "-" instead of "r", it means that there is no read permission.
    • "w" indicates write permission: the permission to change a file. If you see "-" instead of "w", it means that there is no write permission.
    • "x" indicates execution permission: the permission to execute a file, where appropriate. If you see "-" instead of "x", it means that there is no execution permission.

Access rights on directories.

    • "r" allows users to list files in the directory;
    • "w" means that users may delete files from the directory or move files into it.
    • "x" means the right to access files in the directory. This implies that you may read files in the directory provided that you have read permission on the individual files.

So, in order to read a file, you must have execute permission on the directory containing that file, and hence on any directory containing that directory as a subdirectory, and so on, up the tree.

Some examples

-rwxrwxrwx

a file that everyone can read, write and execute (and delete).

-rw-------

a file that only the owner can read and write - no-one else 
can read or write and no-one has execution rights (e.g. your 
mailbox file).

 

Question 7: What are the access rights for folder "test1" and file "test1.txt" in public_html/cs103/lab1/part2? Explain them the same as the above table.

Question 8: Who can delete files inside folder "test1"?

Question 9: Who can access files inside folder "test1"?

Section 3: Changing access rights

I think you have learn so far that every file in world wide web has an owner. Every file also has a group, which determines the file’s "group class." Any system user who is not the owner and does not belong in the same group is determined to be others. Now, the question is how the access rights can be changed?

chmod is a command that stands for “change mode” and allows you to manually change the permission settings of a file. Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as follow:

Symbol

Meaning

u

user

g

group

o

other

a

all

r

read

w

write (and delete)

x

execute (and access directory)

+

add permission

-

take away permission

 

For example, to remove read write and execute permissions on the file test1.txt for the others, type chmod o-rwx test1.txt. To add read permission to all of the users, type chmod a+r test1.txt.

Go to public_html/cs103/lab1/part2 and do the following

    • Make folder "access_right" and go inside this folder.
    • Make folders "test1" & "test2" and text files "test1.txt" and "test2.txt".
    • Question 10: What are the access rights of these 4 files and folders? (write down the 10 symbol string consisting of the symbols d, r, w, x and -)
    • Give read, write and execution permission to the owner and group for "test1" and "test1.txt".
    • Remove read write and execution permission from other for "test2" and "test2.txt".
    • Question 11: What are the new access rights of these folders and files? (write down the 10 symbol string consisting of the symbols d, r, w, x and -)
    • Open your browser (e.g. Firefox) and go to the following URL:

cs-people.bu.edu/Your_BU_UserName/cs103/lab1/part2 /access_right

    • You are supposed to see 2 files ("test1.txt" and "test2.txt") and two folders ("test1" and "test2").
    • Question 12: Do you see all of them? If do not, which ones can you see? Explain your observation.
    • Now, first click on "test1.txt" and then click on "test2.txt".
    • Question 13: What is your observation? Explain it.

If you are reading this line, it means that you have finished your first CS 103 lab assignment. Congratulations!!!

References:

    • https://www.hostinger.com/tutorials/ssh/basic-ssh-commands#gref
    • http://www.ee.surrey.ac.uk/Teaching/Unix/unix5.html
    • https://www.makeuseof.com/tag/chmod-command-linux-file-permissions/

Submit the Assignment

Please prepare your assignment by making the following items in a Microsoft Word document:

    1. Write down your full name and your BU username on top of the page.
    2. Write down the answers of 13 questions of lab1-part2.
    3. Save this document as a PDF file and name it "Lab1-Part2.pdf".
    4. Lab1-Part2.pdf should be a one-page document. Try to include all of the answers in the same page.
    5. Please go to Gradescope and submit the PDF file.

Submit a Review

After completion of Lab1-Part2, Please go to this Microsoft Form and give us your answers.

    • Go to Microsoft Form.
    • Type your BU email address and press enter.
    • Then, use your BU email address and password to sign in to the Microsoft Form.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值