Linux

60Access Windows Shares from Linux
( a ) Mount Windows share using mount command

Windows share can be mounted on RHEL system using cifs option of mount command as :

# mount -t cifs -o username=<share user>,password=<share password> //WIN_PC_IP/<share name> /mnt

In case your user is in windows domain then you can define the domain as follows:

# mount -t cifs -o username=<share user>,password=<share password>,domain=example.com //WIN_PC_IP/<share name> /mnt

example:

#mount -t cifs -o username=ahmet,password=deneme12,domain=itmug //192.168.16.30/share /windowsshare

By default windows share mounted with the full permission (777) in Linux. To change the default permission use the dir_mode and file_mode options to set directory and file permission.

# mount -t cifs -o username=<share user>,password=<share password>,dir_mode=0755,file_mode=0755 //WIN_PC_IP/<share name> /mnt
To make the mount persistant across reboots, make the below entry to the /etc/fstab

//WIN_PC_IP/<share name> /<mntpoint> cifs _netdev,username=<share user>,password=<share password>,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0

( b ) browser a samba / windows share from a command prompt

smbclient \\\\WIN_PC_IP\\<share name> -W workgroup -U username%password

Once the client is running, the user is presented with a prompt, “smb: \>”.

The commands available are given here in alphabetical order.

Note that all commands operating on the server are actually performed by issuing a request to the server.

? [command] If command is specified, the ? command will display a brief informative message about the specified command.If no command is specified, a list of available commands will be displayed.
! [shell command] If shell command is specified, the ! command will execute a shell locally and run the specified shell command. If no command is specified, a shell will be run.
cd [directory name] If directory name is specified, the current working directory on the server will be changed to the directory specified. This operation will fail if for any reason the specified directory is inaccessible.If no directory name is specified, the current working directory on the server will be reported.
del mask The client will request that the server attempt to delete all files matchingmask from the current working directory on the server.
dir mask A list of the files matching mask in the current working directory on the server will be retrieved from the server and displayed.
exit Terminate the connection with the server and exit from the program.
get remote-file-name [local-file-name] Copy the file called remote-file-name from the server to the machine running the client. If specified, name the local copy local-file-name. Note that all transfers in smbclient are binary. See also the lowercase command.
help [command] Same as the ? command.
lcd [directory name] If directory name is specified, the current working directory on the local machine will be changed to the directory specified. This operation will fail if for any reason the specified directory is inaccessible.If no directory name is specified, the name of the current working directory on the local machine will be reported.
lowercase Toggle lowercasing of filenames for the get and mget commands.When lowercasing is toggled ON, local filenames are converted to lowercase when using the get and mget commands. This is often useful when copying (for instance) MSDOS files from a server, because lowercase filenames are the norm on UNIX systems.
ls mask Same as the dir command.
mask mask This command allows the user to set up a mask which will be used during recursive operation of the mget and mput commands.The masks specified to the mget and mput commands act as filters for directories rather than files when recursion is toggled ON.The mask specified with the mask command is necessary to filter files within those directories. For example, if the mask specified in an mget command is “source*” and the mask specified with the mask command is “*.c” and recursion is toggled ON, the mget command will retrieve all files matching “*.c” in all directories below and including all directories matching “source*” in the current working directory.Note that the value for mask defaults to blank (equivalent to “*“) and remains so until the mask command is used to change it. It retains the most recently specified value indefinitely. To avoid unexpected results it would be wise to change the value of mask back to “*” after using the mget or mputcommands.
md directory name Same as the mkdir command.
mget mask Copy all files matching mask from the server to the machine running the client.Note that mask is interpreted differently during recursive operation and non-recursive operation; refer to the recurse and mask commands for more information. Note that all transfers in smbclient are binary. See also thelowercase command.
mkdir directory name Create a new directory on the server (user access privileges permitting) with the specified name.
mput mask Copy all files matching mask in the current working directory on the local machine to the current working directory on the server.Note that mask is interpreted differently during recursive operation and non-recursive operation; refer to the recurse and mask commands for more information. Note that all transfers in smbclient are binary.
print file name Print the specified file from the local machine through a printable service on the server.See also the printmode command.
printmode[graphics|text] Set the print mode to suit either binary data (such as graphical information) or text. Subsequent print commands will use the currently set print mode.
prompt Toggle prompting for filenames during operation of the mget and mputcommands.When toggled ON, the user will be prompted to confirm the transfer of each file during these commands. When toggled OFF, all specified files will be transferred without prompting.
put local-file-name [remote-file-name] Copy the file called local-file-name from the machine running the client to the server. If specified, name the remote copy remote-file-name. Note that all transfers in smbclient are binary. See also the lowercase command.
queue Displays the print queue, showing the job id, name, size and current status.
quit Same as the exit command.
rd directory name Same as the rmdir command.
recurse Toggle directory recursion for the commands mget and mput.When toggled ON, these commands will process all directories in the source directory (i.e., the directory they are copying from) and will recurse into any that match the mask specified to the command. Only files that match themask specified using the mask command will be retrieved. See also themask command. When recursion is toggled OFF, only files from the current working directory on the source machine that match the mask specified to the mget or mput commands will be copied, and any mask specified using the mask command will be ignored.
rm mask Remove all files matching mask from the current working directory on the server.
rmdir directory name Remove the specified directory (user access privileges permitting) from the server.
tar c|x[IXbgNa] Performs a tar operation; see the -T command line option above. Behavior may be affected by the tarmode command (see below). Using g(incremental) and N (newer) will affect tarmode settings. Note that using the “” option with tar x may not work; use the command line option instead.
blocksize blocksize Blocksize. Must be followed by a valid (greater than zero) blocksize. Causes tar file to be written out in blocksize*TBLOCK (usually 512 byte) blocks.
tarmodefull|inc|reset|noreset Changes tar‘s behavior with regard to archive bits. In full mode, tar will back up everything regardless of the archive bit setting (this is the default mode). In incremental mode, tar will only back up files with the archive bit set. In reset mode, tar will reset the archive bit on all files it backs up (implies read/write share).

 

About sftp

sftp is a program for transferring files securely.

Syntax

sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]      [-D sftp_server_path] [-F ssh_config] [-i identity_file]      [-l limit] [-o ssh_option] [-P port] [-R num_requests]      [-S program] [-s subsystem | sftp_server] hostsftp [user@]host[:file …]

sftp [user@]host[:dir[/]]

sftp -b batchfile [user@]host

 

How to run the sftp command with a password?

Use lftp in order to pass multiple command to sftp server, as an example user password

 

Syntax

lftp sftp://user:password@host

 

Leave a comment